aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Warn users of DELETE_SKIPPED events

Open jgondron opened this issue 7 years ago • 1 comments

:rocket: Feature Request

General Information

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

Description

The default removalPolicy for resources that have this property is to orphan the resource. Users who are accustomed to using CloudFormation and are used to a "try to delete, then manually resolve any delete issues" may be caught unaware of this behavior. I understand the reasoning behind using this as a default within cdk, but if a user is unaware of this it can cause orphaned resources that cost $.

Proposed Solution

I see two options here, but am not sure of which is most feasible within cdk:

  1. Examine the resources for any that have a removalPolicy of RemovalPolicy.RETAIN that will be orphaned by the changeset and prompt the user to continue (similar to IAM changes).
  2. Parse the events for the user and callout any DELETE_SKIPPED events a bit better.

Environment

  • CDK CLI Version: 1.4.0 (build 175471f)
  • Module Version: 1.5.0
  • OS: OSX Mojave
  • Language: TypeScript

Other information

Here's a recent example that I've hit. If a user creates a new CodePipeline:

new codepipeline.Pipeline(this, {...});

This will, by default, create a new S3 bucket for it's artifacts and a Customer Managed KMS key to use for encryption. If the user sees this and decides to use an existing managed key instead, they have to explicitly create the bucket and specify the key:

const encryptionKey = Key.fromKeyArn(this, 'awsManagedS3Key', Fn.sub('arn:aws:kms:${AWS::Region}:${AWS::AccountId}:alias/aws/s3'));
const artifactBucket = new s3.Bucket(this, 'artifactBucket', { encryptionKey });
new codepipeline.Pipeline(this, 'ServicePipeline', { artifactBucket, ... });

On the next deploy, CloudFormation will create a new S3 bucket referencing the existing key, but will skip deleting the old bucket and KMS key. Unless the user watches closely for DELETE_SKIPPED from the CloudFormation events, the user will be unaware of what happened, leaving resources that can accumulate cost over time.

jgondron avatar Aug 28 '19 15:08 jgondron

It aligns with CloudFormation behaviour. Why make it dis-aligned?

Note The AWS CDK's RemovalPolicy translates to AWS CloudFormation's DeletionPolicy, but the default in AWS CDK is to retain the data, which is the opposite of the AWS CloudFormation default.

oonisim avatar May 06 '20 02:05 oonisim