Adding S3 trigger to Lambda function using CloudFormation

若如初见. 提交于 2020-01-06 09:03:13

问题


I'm trying to add an S3 trigger to a lambda function using CloudFormation. From what I've read about circular references the lambda function and S3 bucket needs to be created first, which I've done with a template and they get created successfully.

Then I go into "Update Stack" and enter the template:

 "Resources": {
        "MyBucket": {
            "Type": "AWS::S3::Bucket",
            "NotificationConfiguration": {
                "LambdaConfigurations": [
                    {
                        "Event": "s3:ObjectCreated:*",
                        "Function": "arn:aws:lambda:ap-southeast-2:newlyCreatedLambda"
                    }
                ]
            },
            "Properties": {
                "BucketName": "MyBucket"
....
....

But when I try to deploy it gives the error:

Template is not valid: Invalid template resource property 'NotificationConfiguration'

Any idea how to get the trigger added or what I'm doing wrong?


回答1:


Here's what we use:

"BucketForFunctionsAcesImportNewFileUploaded": {
  "Type": "AWS::S3::Bucket",
  "Properties": {
    "NotificationConfiguration": {
      "TopicConfigurations": [],
      "QueueConfigurations": [],
      "LambdaConfigurations": [
        {
          "Function": {
            "Fn::GetAtt": [
              "FunctionsAcesImportNewFileUploaded",
              "Arn"
            ]
          },
          "Event": "s3:ObjectCreated:*"
        }
      ]
    },
    "VersioningConfiguration": {
      "Status": "Suspended"
    }
  },
  "DeletionPolicy": "Delete"
}


来源:https://stackoverflow.com/questions/51991413/adding-s3-trigger-to-lambda-function-using-cloudformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!