我使用nodejs-ssimple-sdk执行了以下方法将事件通知添加到s3 bucket来自ec2实例。
var params={
Bucket: name,
NotificationConfiguration: {
QueueConfigurations: [],
TopicConfigurations: [],
LambdaFunctionConfigurations: [{
"Id": "enableS3EventForTransformCurLambda",
"LambdaFunctionArn": arn,
"Events": [ "s3:ObjectCreated:*" ],
"Filter": { "Key": { "FilterRules": [ { "Name": "Suffix", "Value": ".json" } ] } }
}
]
}
}
const notifevent = await s3.putBucketNotificationConfiguration(paramsNotif).promise();
现在我得到错误
InvalidArgument: Unable to validate the following destination configurations
它构造了正确的参数
我能够通过向s3事件触发的Lambda添加权限来解决这个问题。
旁路
async function addPermissionToLambda(){
var lambda = new AWS.Lambda();
var paramsForNotification = {
Action: "lambda:InvokeFunction",
FunctionName: "lambda-fn",
Principal: "s3.amazonaws.com",
SourceAccount: acctNum,
SourceArn: "arn:aws:s3:::*-test-bucket",
StatementId: "s3LambdaInvokeViaS3Event"
};
var paramsForGetPolicy = {
FunctionName: "lambda-fn"
};
try{
const permission = await lambda.addPermission(paramsForNotification).promise()
console.log("Permission Added to the lambda for invoke it")
}catch(err){
console.log("Error occured while addding permissioon to lambda")
console.log(err, err.stack)
}
}
现在,您可以轻松地将事件通知添加到bucket中。