首页 > 解决方案 > 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

它构造正确的参数

标签: node.jsamazon-web-servicesamazon-s3amazon-ec2

解决方案


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

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


推荐阅读