python - 连接到 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
解决方案
- 我认为这只是一个错字,你需要使用
Key
而不是key
错误所说的。
s3_client.put_object(Bucket=bucket_name, Key=outbound_bucket_key, Body=output_path)
- 所有这些都是首字母大写
Bucket
,Key
,Body
。
推荐阅读
- linux - 开启SMP时判断当前进程是否正在运行
- batch-file - 制作静默安装程序以将文件从文件复制到 C:\Program Files\... 并在开始菜单中制作快捷方式
- python - Python RuntimeError: failed to find interpreter for Builtin discover of python_spec='ackages.venvs/lpthw'
- java - 返回对象的方法抛出异常不处理,如何解决?
- python - ManagementForm 数据在 django 中丢失或被篡改
- procmail - procmail:在保存 Maildir 格式消息时让 procmail 排除主机名
- python - UnicodeEncodeError:“utf-8”编解码器无法编码位置 1418-1419 中的字符:不允许代理
- android - Android Seekbar 值在某些设备上不会为负数
- r - 对数据表进行排序后,我可以选择一个值,取消排序,然后将该值及其下方的 5 个值保存到数据框中吗?
- python-sphinx - Sphinx readthedocs 安装目录的布局与在我自己的机器上安装不同。如何使它们相同?