尝试使用预先签名的URL上传文件,并尝试了stackoverflow的所有解决方案,但对我没有用。 Lambda拥有S3的完全访问权限似乎不是关键问题,但出现以下错误:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>AKIAZRFKVHH444H7KZHN</AWSAccessKeyId>
<StringToSign>AWS4-HMAC-SHA256
找到我尝试的代码:
xsdfileurl= s3_con.generate_presigned_url(
ClientMethod='put_object',
Params={
'Bucket': event["Bucketname"],
'Key': "{}/{}".format("CR001CN001/1", event["Files"][0]),
},
ExpiresIn=6000)
print(xsdfileurl)
任何帮助将不胜感激。
答案 0 :(得分:0)
我自己整天浪费在寻找根本原因上,发现一个愚蠢的错误,即存储桶中缺少CORS配置。
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>