Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a construct to ease S3 bucket migration
A small construct that can be used to prevent orphaning of a bucket when migrating from YAML to GuCDK. As S3 bucket names have a global namespace, it is best practice to set the `DeletionPolicy` attribute of a CloudFormed bucket. Use this construct to retain the logicalId of the bucket resource when migrating from YAML to GuCDK to prevent orphaning and GuCDK attempting to recreate an existing bucket. For example, lets have this YAML template: ```yaml ConfigBucket: Type: AWS::S3::Bucket DeletionPolicy: Retain Properties: BucketName: my-config-bucket ``` If we were to use the standard Bucket construct when migrating this stack to GuCDK, the resulting template would look like: ```yaml ConfigBucketABCD1234: Type: AWS::S3::Bucket DeletionPolicy: Retain Properties: BucketName: my-config-bucket ``` The logicalId has changed and `ConfigBucket` would be deleted. As the `DeletionPolicy` of `ConfigBucket` is set to `Retain`, the bucket will be orphaned, not deleted. This will cause issues for `ConfigBucketABCD1234` as it will try to create a bucket of the same name ("my-config-bucket") and fail as that name is already in use. Use `GuMigratingS3Bucket` to retain the logicalId: ```typescript new GuMigratingS3Bucket(stack, "ConfigBucket", { bucketName: "my-app-config", existingLogicalId: { logicalId: "ConfigBucket", reason: "Prevent orphaning of an S3 bucket" }, }); ``` This will yield: ```yaml ConfigBucket: Type: AWS::S3::Bucket DeletionPolicy: Retain Properties: BucketName: my-config-bucket ``` See: - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
- Loading branch information