Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdk destroy failed to destroy s3 bucket after codepipeline push artifact #1269

Closed
mouyigang opened this issue Dec 2, 2018 · 4 comments
Closed
Labels
@aws-cdk/aws-s3 Related to Amazon S3 feature-request A feature should be added or improved.

Comments

@mouyigang
Copy link

My demo app builds codebuild and codepipeline, after two commits to codecommit and successfully build, I decided to destroy everything:

constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
    super(parent, name, props);
    //codecommit
    const sourcerepo = codecommit.Repository.import(this, 'Repository' ,{
      repositoryName: 'Myrepo'
    });
    //codebuild
    const codebuildproject = new codebuild.Project(this, 'MyProject', {
      source: new codebuild.CodeCommitSource({
          repository: sourcerepo
      }),
    });

    //codedeploy
    
    //codepipeline

    const artifactBucket = new s3.Bucket(this, 'MyBucket', {
      versioned: true, // a Bucket used as a source in CodePipeline must be versioned
    });
    const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
      pipelineName: 'MyPipeline',
      artifactBucket: artifactBucket
    });
    const sourceStage = pipeline.addStage('Source');
    sourcerepo.addToPipeline(sourceStage, 'CodeCommit');

    const buildStage = pipeline.addStage('Build');
    new codebuild.PipelineBuildAction(this, 'CodeBuild', {
      stage: buildStage,
      project: codebuildproject,
    });

  }

But s3 bucket was not deleted:

  8 | 12:26:05 PM | DELETE_FAILED        | AWS::S3::Bucket             | MyBucket (MyBucketF68F3FF0) The bucketyou tried to delete is not empty. You must delete all versions in the bucket. (Service: Amazon S3; Status Code: 409; Error Code: BucketNotEmpty; Request ID: 0FE413930A278D6C; S3 Extended Request ID: +6jGRm6H9mNSfDxJlT0Z8VyQMv3AjG8LcpkgeV6/tI78ET1TXyI8PmezGlznaGRC17cFIJK50o4=)
        new Bucket (/xxx/node_modules/@aws-cdk/aws-s3/lib/bucket.js:253:26)
        \_ new CdkTemplateStack (/xxx/bin/cdk-template.js:34:32)
        \_ Object.<anonymous> (xxx/bin/cdk-template.js:51:1)
        \_ Module._compile (internal/modules/cjs/loader.js:688:30)
        \_ Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
        \_ Module.load (internal/modules/cjs/loader.js:598:32)
        \_ tryModuleLoad (internal/modules/cjs/loader.js:537:12)
        \_ Function.Module._load (internal/modules/cjs/loader.js:529:3)
        \_ Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
        \_ startup (internal/bootstrap/node.js:285:19)
        \_ bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

Expect:
Either state that cdk destroy doesn't destroy s3 buckets, or successfully delete s3 bucket.

@rix0rrr
Copy link
Contributor

rix0rrr commented Dec 2, 2018

You are right, we should be making this easier.

@rix0rrr rix0rrr added feature-request A feature should be added or improved. @aws-cdk/aws-s3 Related to Amazon S3 labels Dec 2, 2018
@rix0rrr rix0rrr changed the title cdk destroy failed to destroy s3 bucket after codepipeline push artifact bucket: add 'retain' property Dec 2, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Dec 2, 2018

We should make it possible to configure the retention policy at the L2 level, and probably default it to true (to satisfy most use cases).

@rix0rrr
Copy link
Contributor

rix0rrr commented Dec 3, 2018

Aha, my mistake. We already have this property.

If you create your bucket like this:

new s3.Bucket(this, 'Bucket', {
   /// ...
  removalPolicy: cdk.RemovalPolicy.Orphan
});

Stack deletion will not complain.

@rix0rrr rix0rrr changed the title bucket: add 'retain' property cdk destroy failed to destroy s3 bucket after codepipeline push artifact Dec 3, 2018
rix0rrr added a commit that referenced this issue Dec 3, 2018
Switch the default RemovalPolicy of a Bucket to Orphan.

This reduces friction for users with stacks that contain Buckets. In the
99% of cases right now, any activity on a Bucket will cause the stack to
fail to delete, and customers are left wondering how to fix this
situation (see #1269 for example).

It seems better to default to the frictionless case, and have people
opt-in to hard deletes if they know for a fact the operation is going to
work.
rix0rrr added a commit that referenced this issue Dec 6, 2018
Switch the default RemovalPolicy of a Bucket to Orphan.

This reduces friction for users with stacks that contain Buckets. In the
99% of cases right now, any activity on a Bucket will cause the stack to
fail to delete, and customers are left wondering how to fix this
situation (see #1269 for example).

It seems better to default to the frictionless case, and have people
opt-in to hard deletes if they know for a fact the operation is going to
work.
@rix0rrr
Copy link
Contributor

rix0rrr commented Dec 6, 2018

We've made the orphaning behavior default. For new stacks, you will not experience this behavior anymore.

@rix0rrr rix0rrr closed this as completed Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

2 participants