首页 > 解决方案 > Adding S3 trigger to Lambda function using CloudFormation

问题描述

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?

标签: amazon-s3aws-lambdaamazon-cloudformation

解决方案


这是我们使用的:

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

推荐阅读