【发布时间】:2019-12-21 07:04:23
【问题描述】:
我正在使用 AWS lambda 函数实现图像处理算法。我想从 S3 存储桶中的“子文件夹”/前缀收集图像,使用 boto3 运行我的算法,并将处理后的图像上传到同一 S3 存储桶中的不同“子文件夹”/前缀。
我还没有成功地在同一个 S3 存储桶内或在前缀下移动图像。我可以使用 boto3 资源或客户端从存储桶中的“根”文件夹下载图像,然后将处理后的图像上传到不同的存储桶。但是,我未能成功访问“子文件夹”/前缀中的图像。
def lambda_handler(event, context):
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
file_path = '/tmp/' + key
s3_client.download_file(bucket, key, file_path)
# call image processing algorithm here
s3_client.upload_file(file_path, 'bucket/folder_a/folder_b', key)
与事件一起传递的密钥是'folder_a/folder_b/IMG_X.jpg'。我一直收到文件未找到错误。
【问题讨论】:
标签: python amazon-s3 aws-lambda boto3