我已按照本教程使用AWS Lambda创建图像缩略图到另一个存储桶:http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-upload-zip-test.html
我已完成本教程前面的所有步骤,但是当我从上面的链接运行Lambda测试中的以下代码时
{
"Records":[
{
"eventVersion":"2.0",
"eventSource":"aws:s3",
"awsRegion":"us-east-1",
"eventTime":"1970-01-01T00:00:00.000Z",
"eventName":"ObjectCreated:Put",
"userIdentity":{
"principalId":"AIDAJDPLRKLG7UEXAMPLE"
},
"requestParameters":{
"sourceIPAddress":"127.0.0.1"
},
"responseElements":{
"x-amz-request-id":"C3D13FE58DE4C810",
"x-amz-id-2":"FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD"
},
"s3":{
"s3SchemaVersion":"1.0",
"configurationId":"testConfigRule",
"bucket":{
"name":"sourcebucket",
"ownerIdentity":{
"principalId":"A3NL1KOZZKExample"
},
"arn":"arn:aws:s3:::sourcebucket"
},
"object":{
"key":"HappyFace.jpg",
"size":1024,
"eTag":"d41d8cd98f00b204e9800998ecf8427e",
"versionId":"096fKKXTRTtl3on89fVO.nfljtsv6qko"
}
}
}
]
}
我收到错误消息
无法调整sourcebucket / HappyFace.jpg的大小并上传到 sourcebucketresized / resized-HappyFace.jpg由于错误: PermanentRedirect:您尝试访问的存储桶必须是 使用指定的端点寻址。请发送所有未来 请求此端点。 END RequestId:345345 ...
我更改了存储桶名称,eTag和图像名称。我需要改变别的吗?我的地区是正确的。我是否需要编辑" principalId"?我在哪里可以找到它?
出了什么问题。
答案 0 :(得分:4)
在我的情况下,问题是桶区域。在示例" us-east-1"使用,但我的水桶在" eu-west-1",所以我不得不改变两件事:
"awsRegion":"eu-west-1",
AWS.config.update({"region": "eu-west-1"})
当然,您仍然需要在lambda测试文件中设置以下值:
name: 'your_bucket_name_here',
arn: 'arn:aws:s3:::your_bucket_name_here'
经过这些修改后,它按预期工作
答案 1 :(得分:0)
你的问题是关于"端点"。你必须改变" arn":" arn:aws:s3 ::: sourcebucket" to" arn":" arn:aws:s3 :::( name_of_your_bucket)"。与" name"相同:" sourcebucket" to" name":"(name_of_your_bucket)"。
为了避免更多问题,您必须将名为HappyFace.jpg的jpg上传到您的存储桶或更改s3放置测试对象代码。
此致
答案 2 :(得分:0)
尝试使用此更新格式(请仔细配置密钥,存储桶名称,arn和awsRegion到您自己的设置):
{
"Records": [
{
"eventVersion": "2.0",
"eventTime": "1970-01-01T00:00:00.000Z",
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"s3": {
"configurationId": "testConfigRule",
"object": {
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901",
"key": "HappyFace.jpg",
"size": 1024
},
"bucket": {
"arn": "arn:aws:s3:::myS3bucket",
"name": "myS3bucket",
"ownerIdentity": {
"principalId": "EXAMPLE"
}
},
"s3SchemaVersion": "1.0"
},
"responseElements": {
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
"x-amz-request-id": "EXAMPLE123456789"
},
"awsRegion": "us-east-1",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"eventSource": "aws:s3"
}
]
}