Right now I am using a template in such a way:
- Create initial resources
- Import existing resources (S3)
- Update stack with new resources depending on existing resources
This is boring because I have to deploy the stack in a 3-step process, commenting out depending on resources.
I've read about cloudformation modules but they don't seem to solve the problem with merging 3-step process (init, import existing, use existing) into single cloudformation template.
Is there a solution for such a case?
UPD: I do understand that I can just use resource ARN to reference existing resources without importing them but it doesn't solve the case where I need to attach additional things to my resources (here I create event notification to imported S3 bucket):
# Import existing resource
S3DataBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
# Modify template by adding event configuration
S3DataBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:Put
Filter:
S3Key:
Rules:
- Name: prefix
Value: !Ref SomePrefix
Function: !GetAtt SomeLambda.Arn
CodePudding user response:
Looks like there is an issue open for this, but AWS aren't too interested in fixing it: https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/79
In the mean time, you could consider a few of things:
- AWS have suggested a workaround using eventbridge: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig-eventbridgeconfig.html#cfn-s3-bucket-eventbridgeconfiguration-eventbridgeenabled
- Does the notification really need to be in the CFN template? Could you just add it manually, the same way that the bucket was added?
- Can you script the "boring work" using the AWS CLI and some JSON/YAML editors or AWS CDK?