【问题标题】:Nodejs SDK: adding s3 bucket eventnotification from aws cli got InvalidArgument: Unable to validate the following destination configurationsNodejs SDK:从 aws cli 添加 s3 存储桶事件通知得到 InvalidArgument:无法验证以下目标配置
【发布时间】:2021-08-27 09:48:49
【问题描述】:

我按照以下方式使用 node js simple sdk 将事件通知添加到 s3 存储桶 来自 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

它构造正确的参数

【问题讨论】:

    标签: node.js amazon-web-services amazon-s3 amazon-ec2


    【解决方案1】:

    我能够通过向从 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)
            }
        
    }
    

    现在您可以轻松地将事件通知添加到存储桶。

    【讨论】:

      猜你喜欢
      • 2018-04-23
      • 2021-07-04
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-11-02
      • 2019-12-14
      • 2020-06-06
      • 2019-09-06
      相关资源
      最近更新 更多