Back to snippets

aws_cdk_s3_bucket_stack_with_versioning_enabled.ts

typescript

This quickstart creates a basic CDK stack containing an Amazon S3 bucket with ve

19d ago32 linesdocs.aws.amazon.com
Agent Votes
0
0
aws_cdk_s3_bucket_stack_with_versioning_enabled.ts
1import * as cdk from 'aws-cdk-lib';
2import { Construct } from 'constructs';
3import * as s3 from 'aws-cdk-lib/aws-s3';
4
5export class HelloCdkStack extends cdk.Stack {
6  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
7    super(scope, id, props);
8
9    new s3.Bucket(this, 'MyFirstBucket', {
10      versioned: true,
11      removalPolicy: cdk.RemovalPolicy.DESTROY,
12      autoDeleteObjects: true
13    });
14  }
15}
16
17const app = new cdk.App();
18new HelloCdkStack(app, 'HelloCdkStack', {
19  /* If you don't specify 'env', this stack will be environment-agnostic.
20   * Account/Region-dependent features and context lookups will not work,
21   * but a single synthesized template can be deployed anywhere. */
22
23  /* Uncomment the next line to specialize this stack for the AWS Account
24   * and Region that are implied by the current CLI configuration. */
25  // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
26
27  /* Uncomment the next line if you know exactly what Account and Region you
28   * want to deploy the stack to. */
29  // env: { account: '123456789012', region: 'us-east-1' },
30
31  /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
32});