[AWS] DevTools Evangelism CDK Edition
Source: Dev.to
Introduction
This is the fourth post in the Japan AWS Top Engineers Advent Calendar 2025.
We’ll discuss the AWS CDK, a commonly used tool for writing IaC code.
While CloudFormation, another AWS IaC tool, is easy to use with any text editor, it can lead to redundant code. The AWS CDK is a bit more difficult to set up, but it allows you to write IaC code efficiently with less code.
Japan AWS Top Engineers Advent Calendar 2025
What is the AWS CDK?
The AWS Cloud Development Kit (CDK) is a tool for creating Infrastructure as Code (IaC) that codifies infrastructure configuration.
Benefits of IaC
Reduced manual configuration errors and repetitive tasks
Infrastructure can also be defined using the AWS Management Console, but doing it manually each time is time‑consuming and prone to errors. By codifying the configuration, the same code can be reused, eliminating manual mistakes and hassle.
Ease of sharing and version control
Codified infrastructure can be shared within a team as a single block of code. Managing it with a version‑control system makes it easy to track differences, and it also enables testing that the code is defined correctly.
A rough overview can be seen in the following image:

Differences between CloudFormation and CDK
CloudFormation allows detailed definitions, but the resulting IaC code can become very long, leading to increased writing time and reduced readability.
CDK achieves abstraction through constructs. By automatically configuring some definitions, IaC code can be written with fewer lines.
A rough overview of the process:

Initializing AWS CDK
Creating a Project
mkdir my-project
cd my-project
Initialize the CDK project (TypeScript in this example):
cdk init app --language typescript

AWS CDK Implementation Example
Note (Test Environment)
I used Kiro (IDE) on a Windows PC.
Implementing an API using API Gateway, Lambda, and S3
The implementation was done with Amazon Q Developer and Kiro using Vibe coding.
The request was: “Define an API using API Gateway and Lambda. Write the Lambda function in TypeScript. The Lambda function should return a list of files in the S3 bucket.”
During development I consulted Kiro via chat to revise the S3 bucket name and Lambda function name.
Implementation Details
Folder Structure
The Lambda function code resides in the lambda folder, and the CDK IaC code resides in the lib folder.

lib Folder
Stack definitions are placed in files inside this folder.
Imports, Classes, and Constructs
Required modules are imported, the class name and constructor are defined, and each resource is declared.

S3 Bucket Definition
The bucket definition includes:
- bucketName – fixed bucket name (optional; otherwise CDK generates a name like
myprojectstack-mybucket-). - removalPolicy –
DESTROY(deletes the bucket when the stack is deleted). - autoDeleteObjects –
true(allows deletion even if the bucket contains objects).

Lambda Function Definition
The Lambda definition includes:
- functionName – fixed function name (optional; otherwise CDK generates a name like
MyProjectStack-ListFilesFunction-). - runtime – Node.js 20.x.
- handler – entry point in
index.js. - code – source from the
lambda/directory. - environment – passes the bucket name as an environment variable.

The Lambda function retrieves a list of files in the S3 bucket, so read permission is granted to the bucket.
