Bobcares

How to Create S3 bucket AWS CDK

by | Aug 20, 2023

Learn how to create an S3 bucket in AWS with TypeScript and AWS CDK. Our AWS Support team is here to help you with your questions and concerns.

How to Create S3 bucket AWS CDK

If you are looking for a guide to help you set up an S3 bucket in our AWS environment with TypeScript and the AWS CDK, you are in luck.

How to Create S3 bucket AWS CDKBefore we begin, here is a checklist of what we need:

  • An AWS account with access key credentials.
  • Node.js installed on the workstation (version 10.13 or later).
  • AWS CLI installed, or configured.
  • Latest version of the AWS CDK Toolkit installed globally.
  • TypeScript installed.

Let’s Get Started

  1. First, we have to create a new directory for our project.
  2. Then, we must head to the project directory.
  3. After that, it is time to start the CDK project with TypeScript as seen below:

    cdk init app --language typescript

    This will set up the basic structure of our project and install the needed dependencies.

  4. Now, we have to install AWS S3 module:

    npm install @aws-cdk/aws-s3

  5. Then, open the lib/my-project-stack.ts file in our project directory and replace the contents with the following code:

    import * as cdk from '@aws-cdk/core';
    import * as s3 from '@aws-cdk/aws-s3';
    export class BucketResourceStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    // The code that defines your stack goes here
    new s3.Bucket(this, 'MyFirstBucket', {
    bucketName: 'my-first-bucket',
    publicReadAccess: true,
    removalPolicy: cdk.RemovalPolicy.DESTROY
    });
    }
    }

  6. At this point, we have to deploy our stack and create our S3 bucket:

    cdk deploy

  7. Finally, head to our AWS console and navigate to the S3 service. We will be able to see our bucket listed.

Furthermore, we can clean up and remove our bucket if we want to, with this command:

cdk destroy

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Today, our Support Techs demonstrated how to create an S3 bucket in our AWS environment using TypeScript and the AWS CDK.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.