Open In App

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.

Primary Terminologies of AWS CDK

What is AWS CDK?

CDK Constructs

Constructs are further divided into 3 levels L1, L2 and L3:



L1 Constructs

These constructs represent constructs that are defined by cloud formation. These constructs are generated from cloud formation resource specification.

Below is example for L1 construct for S3 bucket which is CfnBucket in javascript:






const gfgbucket = new s3.CfnBucket(stackname, "gfgbucket", {
  bucketName: gfgbucket"
});

Below is example for L1 construct for Dynamo DB which is CfnTable in javascript:




new dynamodb.CfnTable(
   stack name , 
   "gfgtable"
   {
      keySchema: [
         {
            attributeName: props.attributeName,
            keyType: "HASH",
         },
      ],
      attributeDefinitions: [
         {
            attributeName: props.attributeName,
            attributeType: "S",
         },
      ],
   },
);

L2 Constructs

These constructs are higher level constructs built over L1 constructs. These include predefined configurations and methods for configuring services reducing complexity and providing more abstraction.

L3 Constructs

These constructs are top level constructs which are used to define patterns for multiple resource provisioning or designing higher level architectures using AWS CDK.

CDK Stacks and Apps

CDK Apps

CDK Stacks

Benefits of AWS CDK

Using the CDK Toolkit

Now we will see how we can use AWS CDK with javascript.

Step 1: Setup The Environment To Use AWS CDK

npm install aws-cdk-lib

Step 2: Create The App And Initialize With CDK:

cdk init app --language 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

cdk synth

The output will display the YAML for the resource and .out file will be generated.

Step 4: Deploy The Stack

cdk deploy

The command will create a stack in cloud formation and also provision s3 bucket.

Best Practices For Scaling AWS CDK In Your Organization

Conclusion

From this article we had an overlook of AWS Cloud Development Kit. Various use cases of AWS CDK and its working. AWS CDK is a beneficial framework in cloud as the features it offers redefines the process of writing and provisioning cloud resources.

AWS CDK (Cloud Development Kit) – FAQs

How Does AWS CDK Differ From AWS CloudFormation?

While AWS CloudFormation is a declarative language for defining AWS infrastructure as code. AWS CDK allows developers to use imperative programming languages to define infrastructure. CDK generates CloudFormation templates under the hood.

Which Programming Languages Are Supported By AWS CDK?

AWS CDK supports several programming languages, including TypeScript, Python, Java, C#, and others. Developers can choose the language that best suits their preferences and expertise.

Can I Use AWS CDK With Existing AWS Resources?

Yes, AWS CDK can be used with existing AWS resources. You can import existing resources into your CDK application and manage them alongside resources defined in the CDK application.

Is AWS CDK Suitable For Production Environments?

Yes, AWS CDK is suitable for production environments. It is designed to help developers efficiently manage and deploy cloud infrastructure at scale. Many organizations use AWS CDK in their production systems.

How Does AWS CDK Handle Updates And Changes To Infrastructure?

AWS CDK generates AWS CloudFormation templates, and it leverages CloudFormation for stack management. Developers can use CloudFormation features like change sets to review and apply updates to their infrastructure.


Article Tags :