首页 > 解决方案 > 连接到 s3 的 put_object 的 lambda 问题,但 get_object 有效

问题描述

我有一个连接到 s3 并读取文件的 lambda,然后它对文件进行一些操作并将其放回不同的存储桶。我的 lambda 具有连接到 s3 的适当角色,因此这不是问题。我可以将 s3 格式的文件下载到 lambda 上的 /tmp/ 文件夹中并进行更改。但是当我尝试使用 s3_client.put_object 将其放回原处时,它会出现以下错误

s3_client = boto3.client("s3")
# read the file
file_obj = s3.get_object(Bucket=bucket_name, Key=bucket_key)
file_content = file_obj["Body"].read()
# do some manuplation on it and try to upload it back to the s3
s3_client.put_object(Bucket=bucket_name, key=outbound_bucket_key, Body=output_path)
Parameter validation failed:
Missing required parameter in input: "Key"
Unknown parameter in input: "key", must be one of: ACL, Body, Bucket, CacheControl, ContentDisposition, ContentEncoding, ContentLanguage, ContentLength, ContentMD5, ContentType, Expires, GrantFullControl, GrantRead, GrantReadACP, GrantWriteACP, Key, Metadata, ServerSideEncryption, StorageClass, WebsiteRedirectLocation, SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5, SSEKMSKeyId, SSEKMSEncryptionContext, RequestPayer, Tagging, ObjectLockMode, ObjectLockRetainUntilDate, ObjectLockLegalHoldStatus
END RequestId: 88fd1324-7b14-4b24-b414-a0a04bb97bbd
REPORT RequestId: 88fd1324-7b14-4b24-b414-a0a04bb97bbd Duration: 4511.74 ms Billed Duration: 4600 ms Memory Size: 128 MB Max Memory Used: 128 MB Init Duration: 1179.77 ms

标签: pythonamazon-s3aws-lambda

解决方案


  • 我认为这只是一个错字,你需要使用Key而不是key错误所说的。
s3_client.put_object(Bucket=bucket_name, Key=outbound_bucket_key, Body=output_path)

  • 所有这些都是首字母大写Bucket, Key, Body

推荐阅读