项目作者: neilkuan

项目描述 :
AWS CDK Construct Library For Delete Bucket completely.
高级语言: TypeScript
项目地址: git://github.com/neilkuan/cdk-s3bucket.git
创建时间: 2020-09-13T03:37:06Z
项目社区:https://github.com/neilkuan/cdk-s3bucket

开源协议:Apache License 2.0

下载


NPM version
PyPI version
Release

Downloads
npm
PyPI

cdk-s3bucket-ng

cdk-s3bucket-ng is an AWS CDK construct library that provides a drop-in replacement for the Bucket construct with the capability to remove non-empty S3 buckets.

Install

  1. Use the npm dist tag to opt in CDKv1 or CDKv2:
  2. // for CDKv2
  3. npm install cdk-s3bucket-ng
  4. or
  5. npm install cdk-s3bucket-ng@latest
  6. // for CDKv1
  7. npm install cdk-s3bucket-ng@cdkv1

💡💡💡 please click here, if you are using aws-cdk v1.x.x version.💡💡💡

Why

Sometime we just do some lab , create a S3 Bucket.
Want to destroy resource , after Lab finished.
But We forget delete Object in S3 Bucket first , so destroy will fail.

cdk-s3bucket-ng can help delete object when cdk destroy , just add removalPolicy: RemovalPolicy.DESTROY property .

You never have to delete objects yourself, and the usage is almost the same as the native @aws-cdk/aws-s3.Bucket

Now Try It !!!

Sample

  1. import { App, Stack, CfnOutput, RemovalPolicy } from 'aws-cdk-lib';
  2. import { BucketNg } from 'cdk-s3bucket-ng';
  3. import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
  4. // Create a S3 , add props "removalPolicy: RemovalPolicy.DESTROY".
  5. const bucket = new BucketNg(stack, 'Bucket',{
  6. removalPolicy: RemovalPolicy.DESTROY,
  7. });
  8. //Upload temp file .
  9. new s3deploy.BucketDeployment(stack, 'addResource', {
  10. sources: [s3deploy.Source.asset('./testdir')],
  11. destinationBucket: bucket,
  12. });
  13. // Get S3 Resource via bucket.s3Bucket ...
  14. new CfnOutput(stack, 'BucketName', { value: bucket.bucketName });
  1. # create temp file .
  2. mkdir ./testdir
  3. touch ./testdir/{a.txt,b.txt,c.txt}
  4. ls ./testdir
  5. a.txt b.txt c.txt

To deploy

  1. cdk deploy

To destroy

  1. # will delete object in S3 , and delete S3 Bucket
  2. cdk destroy

:clap: Supporters

Stargazers repo roster for @neilkuan/cdk-s3bucket