[英]How to upload downloaded file to s3 bucket using Lambda function
I saw different questions/answers but I could not find the one that worked for me.我看到了不同的问题/答案,但找不到适合我的问题/答案。 Hence, I am really new to AWS, I need your help.
因此,我对 AWS 真的很陌生,我需要你的帮助。 I am trying to download gzip file and load it to the json file then upload it to the S3 bucket using Lambda function.
我正在尝试下载 gzip 文件并将其加载到 json 文件,然后使用 Lambda 函数将其上传到 S3 存储桶。 I wrote the code to download the file and convert it to json but having problem while uploading it to the s3 bucket.
我编写了下载文件并将其转换为 json 的代码,但在将其上传到 s3 存储桶时出现问题。 Assume that file is ready as x.json.
假设该文件已准备好作为 x.json。 What should I do then?
那我该怎么办?
I know it is really basic question but still help needed :)我知道这是非常基本的问题,但仍然需要帮助:)
This code will upload to Amazon S3:此代码将上传到 Amazon S3:
import boto3
s3_client = boto3.client('s3', region_name='us-west-2') # Change as appropriate
s3._client.upload_file('/tmp/foo.json', 'my-bucket', 'folder/foo.json')
Some tips:一些技巧:
/tmp/
/tmp/
If your lambda has proper permission to write a file into S3, then simply use boto3 package which is an AWS SDK for python.如果您的 lambda 具有将文件写入 S3 的适当权限,则只需使用boto3包,它是适用于 Python 的 AWS 开发工具包。
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html
Be aware that if the lambda locates inside of VPC then lambda cannot access to the public internet, and also boto3 API endpoint.请注意,如果 lambda 位于 VPC 内部,则 lambda 无法访问公共互联网,也无法访问 boto3 API 端点。 Thus, you may require a NAT gateway to proxy lambda to the public.
因此,您可能需要一个 NAT 网关来向公众代理 lambda。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.