Let’s dive into AWS CDK with an example

Overview:

The AWS Cloud Development Kit (AWS CDK) is a software development framework for defining your cloud infrastructure in code and provisioning it through AWS CloudFormation.

Use the AWS CDK to define your cloud resources in a familiar programming language. The AWS CDK supports TypeScript, JavaScript, Python, Java, and C#/.Net.

Why use the AWS CDK?

· A small CDK class produces an AWS CloudFormation template of more than hundreds of lines;
· Use logic (if statements, for-loops, etc) when defining your infrastructure
· Use object-oriented techniques to create a model of your system
· Define high-level abstractions, share them, and publish them to your team, company, or community
· Organize your project into logical modules
· Share and reuse your infrastructure as a library
· Testing your infrastructure code using industry-standard protocols
· Use your existing code review workflow
· Code completion within your IDE

Prerequisites: [knowledge about the following]
• AWS CloudFormation
• Java
• git
• node.js

Into example Application:

Install CDK
npm install -g aws-cdk # install latest version
npm install -g aws-cdk@X.YY.Z # install specific version

npm install -g aws-cdk # install latest version npm install -g aws-cdk@X.YY.Z # install specific version

Configure credentials locally https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html

Checkout code from git location https://github.com/awsdocs/aws-doc-sdk-examples

go into folder …\aws-cdk-examples\java\api-cors-lambda-crud-dynamodb

cdk ls

D:\cdk\aws-cdk-examples-master\java\api-cors-lambda-crud-dynamodb>cdk deploy

Once successfully deployed, it will show you the URL for REST API calls.

You can validate the deployments by login into aws account.

Violla, the application is successfully deployed and accessed using postman.

Now we need to remove the deployment for that

cdk destroy

Issues:

The first time you deploy an AWS CDK app into an environment (account/region), you’ll need to install a “bootstrap stack”.

cdk bootstrap

References:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store