Python AWS Boto3:如何从S3存储桶读取文件? [英] Python AWS Boto3: How to read files from S3 bucket?
问题描述
使用Boto3,python脚本从S3存储桶下载文件以读取它们,并将下载文件的内容写入名为blank_file.txt
的文件.
Using Boto3, the python script downloads files from an S3 bucket to read them and write the contents of the downloaded files to a file called blank_file.txt
.
我的问题是,一旦脚本进入AWS Lambda函数,它将如何以相同的方式工作?
My question is, how would it work the same way once the script gets on an AWS Lambda function?
推荐答案
Lambda提供512 MB的 /tmp
空间.您可以使用该挂载点来存储下载的S3文件或创建新文件.
Lambda provides 512 MB of /tmp
space. You can use that mount point to store the downloaded S3 files or to create new ones.
s3client.download_file(bucket_name, obj.key, '/tmp/'+filename)
...
blank_file = open('/tmp/blank_file.txt', 'w')
Lambda使用的工作目录是/var/task
,它是一个只读文件系统.您将无法在其中创建文件.
The working directory used by Lambda is /var/task
and it is a read-only filesystem. You will not be able to create files in it.
这篇关于Python AWS Boto3:如何从S3存储桶读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!