-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
area/cloudformationmaintainer/need-responsepriority/2-importantstage/pm-reviewWaiting for review by our Product Manager, please don't work on this yetWaiting for review by our Product Manager, please don't work on this yettype/feature
Description
If conditional resource creation is eventually supported you might also have to support conditional events as in the following example where in some environments a bucket might not already exist and so it can be created and the event attached to the lambda. While in other environments the bucket may already exist and the trigger needs to be manually defined because cloudformation doesn't yet use existing resources.
For example
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Lambda that responds to S3 events
Parameters:
PreExistingBucket:
Description: "Does an existing bucket exist (not managed by cloudformation)"
Type: String
Default: 'no'
AllowedValues:
- 'yes'
- 'no'
ConstraintDescription: must specify yes or no.
Conditions:
NeedsSomeBucket: !Equals [ !Ref PreExistingBucket, 'no' ]
Resources:
BucketEventConsumer:
Type: AWS::Serverless::Function
Properties:
Handler: BucketEventConsumer.main.lambda_handler
Runtime: python3.6
CodeUri: bundle.zip
Events:
CreateMetaEvent:
Condition: NeedsSomeBucket
Type: S3
Properties:
Bucket: !Ref SomeBucket
Events: "s3:ObjectCreated:*"
Filter:
S3Key:
Rules:
-
Name: suffix
Value: meta.json
SomeBucket:
Condition: NeedsSomeBucket
Type: "AWS::S3::Bucket"
Properties:
BucketName: 'some-bucket-somewhere'
DeletionPolicy: Retain
I'd like to draw your attention to the following crucial lines:
CreateMetaEvent:
Condition: NeedsSomeBucket
Can this already be acheived using Fn::If?
neverendingqs, flatherskevin, ckabalan, zdg-fyayc, amundra2016 and 38 more
Metadata
Metadata
Assignees
Labels
area/cloudformationmaintainer/need-responsepriority/2-importantstage/pm-reviewWaiting for review by our Product Manager, please don't work on this yetWaiting for review by our Product Manager, please don't work on this yettype/feature