【发布时间】:2021-06-20 08:51:52
【问题描述】:
代码使用 AWS SDK for JavaScript 版本 2.868.0 在 AWS Lambda Node.js 14 运行时上运行。
这里是sn-p的代码:
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
exports.handler = async (event) => {
const objectContent = event['getObjectContext'];
const data = await s3.writeGetObjectResponse({
Body: 'test',
RequestRoute: objectContent['outputRoute'],
RequestToken: objectContent['outputToken']
}).promise();
console.log(data);
const response = {
statusCode: 200
};
return response;
};
我已将以下 IAM 策略附加到 Lambda 角色:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowObjectLambdaAccess",
"Action": [
"s3-object-lambda:WriteGetObjectResponse"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
函数在await s3.writeGetObjectResponse(...).promise()这一行抛出如下错误:
2021-03-22T01:59:29.951Z eb99f9a6-75c7-40ec-9f85-e19da084c42c ERROR Invoke Error {
"errorType": "MethodNotAllowed",
"errorMessage": "The specified method is not allowed against this resource.",
"code": "MethodNotAllowed",
"message": "The specified method is not allowed against this resource.",
"region": null,
"time": "2021-03-22T01:59:29.891Z",
"requestId": "C0FKZ5WSK027GPQW",
"extendedRequestId": "+9rRhWJUPgIAmFupxXKrkAIWe5dXbi0vAacoN+/NlCQPgKzyZi0+mpevGMIVDDPo/1EYpo8Ntyk=",
"statusCode": 405,
"retryable": false,
"retryDelay": 15.885104429810148,
"stack": [
"MethodNotAllowed: The specified method is not allowed against this resource.",
" at Request.extractError (/opt/nodejs/node_modules/aws-sdk/lib/services/s3.js:712:35)",
" at Request.callListeners (/opt/nodejs/node_modules/aws-sdk/lib/sequential_executor.js:106:20)",
" at Request.emit (/opt/nodejs/node_modules/aws-sdk/lib/sequential_executor.js:78:10)",
" at Request.emit (/opt/nodejs/node_modules/aws-sdk/lib/request.js:688:14)",
" at Request.transition (/opt/nodejs/node_modules/aws-sdk/lib/request.js:22:10)",
" at AcceptorStateMachine.runTo (/opt/nodejs/node_modules/aws-sdk/lib/state_machine.js:14:12)",
" at /opt/nodejs/node_modules/aws-sdk/lib/state_machine.js:26:10",
" at Request.<anonymous> (/opt/nodejs/node_modules/aws-sdk/lib/request.js:38:9)",
" at Request.<anonymous> (/opt/nodejs/node_modules/aws-sdk/lib/request.js:690:12)",
" at Request.callListeners (/opt/nodejs/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"
]
}
提前致谢。
【问题讨论】:
标签: amazon-web-services amazon-s3 aws-lambda aws-sdk-js