- 新しい順
- 投票が多い順
- コメントが多い順
You’re correct that adding an S3 bucket trigger to a Lambda function using CloudFormation is impossible if the bucket already exists and isn’t defined within the same stack, since NotificationConfiguration can only be specified within the AWS::S3::Bucket resource.
This has been part of the CFN coverage roadmap for ages : https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/79
I can think of some workarounds:
-
SAM : If you're trying to trigger a Lambda function from these S3 events, you can make use of the AWS::Serverless::Function resource and configure its
EventSourceproperty to point to S3. -
Custom Resource : In the Lambda function for this custom resource, use the AWS SDK to programmatically add an event notification to the existing S3 bucket. The function will call s3.putBucketNotificationConfiguration to set up the event for the Lambda function.
-
Use EventBridge as a middle layer : This has been described in https://repost.aws/knowledge-center/eventbridge-rule-monitors-s3
Consider that approaches 1 and 2 would result in the bucket-creator stack to appear drifted.
Hope that helps.
