How to use the CDK Toolkit In AWS
Now we will see how we can use AWS CDK with javascript.
Step 1: Setup The Environment To Use AWS CDK
- Install the aws cdk using below command.
npm install aws-cdk-lib
Step 2: Create The App And Initialize With CDK:
- First create project folder with the name required.
- Go to the folder and initialize the cdk with below command:
cdk init app --language javascript
- Once the app is initialized add stack to your app.
- create a new .js file with stack name. let’s add s3 bucket configuration in stack.
Javascript
const cdk = require( 'aws-cdk-lib' ); const s3 = require( 'aws-cdk-lib/aws-s3' ); class GfgCdkStack extends cdk.Stack { constructor(scope, id, props) { super (scope, id, props); new s3.Bucket( this , 'GfgBucket' , { versioned: true }); } } module.exports = { GfgCdkStack } |
Step 3: Synthesize An AWS CloudFormation Template
- Now synthesize the application using below command.
cdk synth
The output will display the YAML for the resource and .out file will be generated.
Step 4: Deploy The Stack
- Finally run below command to deploy the stack.
cdk deploy
The command will create a stack in cloud formation and also provision s3 bucket.
AWS CDK(Cloud Development Kit)
AWS CDK or Cloud Development Kit is a framework that allows you to use reusable components called constructs to build cloud environments. Developers can build and create cloud services using Integrated Development Environments with the help of libraries and components. AWS CDK provides a simple and easy approach to building infrastructure with the help of programming languages. So, let’s learn more about AWS CDK.