node.js - Nodejs SDK:从 aws cli 添加 s3 存储桶事件通知得到 InvalidArgument:无法验证以下目标配置
问题描述
我按照以下方式使用来自 ec2 实例的节点 js simple sdk 将事件通知添加到 s3 存储桶。
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)
}
}
现在您可以轻松地将事件通知添加到存储桶。
推荐阅读
- c# - 在浏览器中打开文件时无法通过 Microsoft 图形 SDK 更新文件流
- makefile - gnu makefile grep,将变量刷新到右侧
- objective-c - 使用 REGEX 和 Objective-C 的字符串验证(密码用例)
- php - 使用带有 pg_update() PHP 的事务
- c# - 类型参数约束似乎不适用于返回的类型
- yii2 - Model::loadMultiple 不填充模型
- react-native - 带有多个 ScrollView 项目的帧丢失(应用程序冻结)
- jquery - 复选框单击事件为类名触发了两次,而为 id 触发了一次(jquery)
- selenium - 如何在 codeceptjs/量角器中使用 I.attachFile?
- css - 具有许多按钮的页面的用户界面设计