AWS Cloud Development Kit (AWS CDK)
Cloud service · AWS · Updated

AWS Cloud Development Kit (AWS CDK)

In short

The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework designed to model and provision cloud application resources using familiar programming languages.

Cloud Services Hub →

7 key features of AWS Cloud Development Kit (AWS CDK)

AWS CDK empowers developers to define cloud infrastructure in familiar programming languages, reuse components, seamlessly integrate with AWS services, manipulate resources directly, and enforces best practices automatically.

01
Declarative Infrastructure as Code

AWS CDK allows developers to define their cloud infrastructure using familiar programming languages such as TypeScript, Python, Java, and C#. This approach enables the use of conditionals, loops, and abstractions to create complex resources, making infrastructure management more efficient and less error-prone.

02
Reusable Components

Through the use of Constructs, the AWS CDK provides a way to encapsulate and reuse cloud components. Developers can bundle configurations into Constructs and share them within their organization or the broader community, promoting best practices and reducing duplication of effort.

03
Integrated with AWS Services

The AWS CDK comes with high-level components that pre-configure cloud resources with sane defaults, making it easier to integrate various AWS services such as Amazon EC2, Amazon S3, and Amazon DynamoDB into your applications with minimal manual configuration.

04
Logical Resource Manipulation

It enables direct interaction and manipulation of AWS CloudFormation resources, providing a fine-grained control over the cloud resources and facilitating complex deployments that can be difficult to achieve with CloudFormation alone.

05
Built-In Best Practices

AWS CDK incorporates AWS best practices by default, helping users adhere to security, reliability, and efficiency standards without having to be experts in AWS. It intelligently selects resource types and configurations that meet AWS guidelines.

06
Aspects

AWS CDK aspects apply standards to all constructs within a scope by modifying constructs, such as adding tags, or verifying their state.

07
CLI and Programmatic Toolkit

The AWS CDK Toolkit provides both a command-line tool, the CDK CLI, and a programmatic library, the CDK Toolkit Library, for managing and interacting with CDK apps.

Where AWS Cloud Development Kit (AWS CDK) is used

AWS CDK enables infrastructure as code, automated deployments, reusable component libraries, serverless application definition, and simplified permission management and security, enhancing cloud development and operability.

  1. 01
    Infrastructure as Code for Cloud Resources

    AWS CDK allows developers to define their cloud resources using familiar programming languages. This approach to infrastructure as code (IaC) helps in automating deployment and managing infrastructure through versioned code without manually handling resource provisioning.

  2. 02
    Automated Cloud Application Deployment

    With AWS CDK, developers can automatically deploy cloud applications. By scripting the deployment process, AWS CDK simplifies continuous integration and continuous delivery (CI/CD) pipelines, ensuring applications are deployed consistently and with less manual overhead.

  3. 03
    Reusable Cloud Component Libraries

    AWS CDK supports the creation of reusable component libraries. These libraries can be shared within an organization, allowing teams to rapidly deploy standardized and proven cloud infrastructure patterns, improving development speed and reducing errors.

  4. 04
    Serverless Applications

    AWS CDK is instrumental in defining serverless applications. Developers can use high-level abstractions to define functions, APIs, and event source mappings, making it easier to build and deploy serverless architectures on AWS Lambda and related services.

  5. 05
    Permission Management and Security

    Managing permissions and security settings is streamlined with AWS CDK. It provides constructs for defining AWS Identity and Access Management (IAM) roles, policies, and security groups, making it simpler to implement best practices for cloud security.

How AWS Cloud Development Kit (AWS CDK) is priced

AWS CDK is free to use, with costs only occurring for the AWS services provisioned via the CDK.

Free-to-use Model

AWS CDK itself does not incur direct costs for its usage. Developers are only charged for the AWS resources they provision through the CDK based on the pricing of individual AWS services.

Services AWS Cloud Development Kit (AWS CDK) works with

Amazon S3Amazon S3

CDK allows you to create, configure, and manage S3 buckets for object storage.

AWS LambdaAWS Lambda

CDK facilitates the creation and deployment of serverless functions using AWS Lambda.

Amazon EC2Amazon EC2

CDK enables the setup and management of virtual servers and associated resources using EC2.

Amazon Elastic Container Registry (Amazon ECR)Amazon Elastic Container Registry (Amazon ECR)

AWS CDK publishes Docker image assets to Amazon ECR repositories during deployment. Deployed resources can then use those images, such as a container image built from a local directory for an ECS task.

AWS AmplifyAWS Amplify

Amplify Gen 2 builds backend infrastructure using AWS CDK. You can extend an Amplify backend with CDK constructs and connect additional resources to its generated authentication, data, and storage resources.

AWS CloudFormationAWS CloudFormation

AWS CDK synthesizes application stacks into CloudFormation templates and deploys them through CloudFormation. CloudFormation provisions the resources, tracks stack state, and handles updates and rollbacks.

AWS CodeBuildAWS CodeBuild

CDK Pipelines uses CodeBuild projects to synthesize CDK applications, publish assets, and update the pipeline itself. Build steps can also run application tests and deployment validation commands.

AWS CodeCommitAWS CodeCommit

CDK Pipelines supports CodeCommit repositories as pipeline sources. Changes to a configured repository branch can start a pipeline that synthesizes and deploys the CDK application.

What is AWS Cloud Development Kit (AWS CDK)

3 min read

The AWS Cloud Development Kit, also known as AWS CDK, represents a significant leap forward in how cloud resources are provisioned and managed, offering a more dynamic, flexible, and efficient approach to utilizing Amazon Web Services (AWS). 

At its core, the AWS CDK is a software development framework that allows developers to define their cloud infrastructure using familiar programming languages such as TypeScript, Python, Java, and C#. This innovative approach moves away from the traditional JSON or YAML templates used in AWS CloudFormation, towards a more intuitive and developer-friendly model that leverages the power of modern programming practices. 

One of the defining features of the AWS CDK is its ability to enable developers to compose and share their own custom cloud components. What this means in practice is that teams can build and distribute higher-level abstractions that encapsulate cloud best practices or specific business logic, codifying and reusing patterns effectively across their organization. This not only accelerates the development process by reducing redundant effort but also ensures consistency and compliance with organizational standards. 

A CDK app defines one or more stacks, each equivalent to a CloudFormation stack. Each stack contains constructs that define one or more AWS resources.

The AWS CDK integrates deeply with AWS CloudFormation, providing a seamless deployment mechanism. When a developer provisions infrastructure using the CDK, under the hood, the CDK synthesizes CloudFormation templates from the code. This synthesis process converts the higher-level abstraction provided by the CDK into the detailed specification required by CloudFormation to deploy and manage AWS resources. Notably, this dual-layer approach combines the abstract, developer-friendly interface of the CDK with the robust, proven deployment capabilities of CloudFormation, offering the best of both worlds.

CDK checks stack resource counts during synthesis and warns when a stack exceeds 80% of the CloudFormation resource limit. The stack's maxResources property sets a different resource limit for validation; setting it to 0 disables validation.

Another significant advantage of using the AWS CDK is the built-in best practices that come with it. AWS provides a library of pre-built constructs, which are the basic building blocks in the CDK, representing AWS resources and their configurations. These constructs are designed to guide users toward well-architected solutions, automatically handling intricate details such as security configurations, resource dependencies, and other cloud-specific considerations that might otherwise be overlooked. 

The AWS CDK also promotes the Infrastructure as Code (IaC) paradigm, allowing entire cloud infrastructure setups to be version-controlled alongside application code. This facilitates better collaboration among team members, simplifies the rollback of changes, and enhances the overall auditability of the infrastructure. Coupled with the power of modern integrated development environments (IDEs) and tools, developers can enjoy features like code completion, syntax highlighting, and error detection in real-time as they define their cloud infrastructure, making the process both more efficient and less prone to errors. 

In summary, the AWS Cloud Development Kit is a powerful tool that modernizes cloud infrastructure provisioning by marrying conventional coding practices with cloud resource management. It not only streamlines the development and deployment processes but also encourages best practices and consistency across teams and projects. As cloud computing continues to evolve, tools like the AWS CDK will play an instrumental role in shaping the future of how applications and services are deployed in the cloud.

AWS Cloud Development Kit (AWS CDK) exam questions

Real practice exam questions on AWS Cloud Development Kit (AWS CDK), with the correct answer and its explanation. Answer them with every option in the exam simulator.

SOA-C03

A company uses a shared construct library in a TypeScript AWS CDK application. The library creates an Amazon S3 bucket by using an L2 Bucket construct and exposes that construct to the application. The bucket is already deployed without versioning. The shared library does not provide an option to enable versioning.

A CloudOps engineer must enable versioning on the existing bucket through the application's CDK source code without modifying the shared library or creating another bucket. The deployment pipeline regenerates the CloudFormation template from the application before every deployment.

Which solution meets these requirements?

Show answerCORRECT ANSWER

Access the exposed Bucket construct's node.defaultChild, cast it to CfnBucket, and set its versioningConfiguration status to Enabled before synthesis.

The L2 Bucket construct contains an underlying L1 CfnBucket resource. Using this escape hatch changes the properties synthesized for the same CloudFormation resource. CloudFormation can enable versioning on the existing bucket in place, and the change remains reproducible from the application's source code.

SAP-C03

A company uses AWS CDK applications to define infrastructure for several environments. Each application contains multiple CDK Stage constructs, and each Stage contains several stacks. Teams create S3 buckets by using company libraries, third-party constructs, and low-level CloudFormation resource constructs.

A new policy requires every bucket defined by these applications to have versioning explicitly enabled. All versioning settings are concrete values available during synthesis. The platform team must provide a reusable control that reports each violation with its construct path and causes pull-request validation to fail before any deployment. Validation must run without AWS credentials or access to AWS service endpoints. The control must not silently modify resource settings.

Which solution best meets these requirements?

Show answerCORRECT ANSWER

Create a reusable CDK aspect that inspects every CfnBucket and adds an error annotation when versioning is not explicitly enabled. Attach the aspect to each Stage, and require successful synthesis in pull-request validation.

An aspect can inspect the construct tree during synthesis. Inspecting CfnBucket resources covers buckets created through higher-level libraries as well as directly through low-level constructs. Error annotations identify offending construct paths and cause synthesis to fail without modifying resources. Aspects do not propagate across Stage boundaries, so attaching the aspect to each Stage ensures coverage of its stacks. These checks can run locally without AWS API calls.

DEA-C01

A data engineering team uses AWS CDK to deploy AWS Glue jobs from a dataset configuration file. The application creates each job with a construct ID that includes the dataset name and the current timestamp. CloudFormation generates the physical job names. Each deployment targets the same stack in the same account and Region.

The CI/CD system sometimes reruns deployment after losing its connection, even when the previous deployment completed successfully. The team notices that deploying unchanged code and configuration produces new Glue jobs and removes the previous jobs.

Which change will ensure that repeated deployments of unchanged code and configuration preserve the existing jobs without requiring manual intervention?

Show answerCORRECT ANSWER

Use a stable construct ID derived from each dataset's unique configuration key, and keep the construct hierarchy unchanged between deployments.

CDK derives CloudFormation logical IDs from construct paths. Stable construct IDs and hierarchy preserve resource identity. When the code and configuration are unchanged, repeated deployments target the existing jobs instead of creating replacements, making retries safe.

Practice AWS Cloud Development Kit (AWS CDK) in a full exam

Questions on AWS Cloud Development Kit (AWS CDK) in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

Learn AWS Cloud Development Kit (AWS CDK) in lessons

11 short lessons on AWS Cloud Development Kit (AWS CDK) in 5 certification courses.

and 5 more lessons

Open the lessons

AWS architecture icons are the property of Amazon Web Services. BlowStack is not affiliated with or endorsed by AWS.