I Added a Feature to an AWS CDK Blocks Template and Ran It Locally and in an AWS Sandbox #AWSreInvent

I Added a Feature to an AWS CDK Blocks Template and Ran It Locally and in an AWS Sandbox #AWSreInvent

I built a TODO app with the AWS CDK Blocks react template, added due dates and a CronJob overdue check, verified them in a cloud dev environment without AWS credentials, then deployed to real AWS in a sandbox.
2026.12.01

This page has been translated by machine translation. View original

Hello, I'm Shunta Toda from the Retail App Co-creation Department.

The other day, I wrote an article giving a rough overview of AWS CDK Blocks, which was introduced in a re:Invent 2026 session.
With CDK Blocks, you write your backend by combining Blocks such as "KVStore" and "Auth"; locally it runs on each Block's local implementation, and on AWS the corresponding resources are deployed with CDK.
As a follow-up, this time I'll build a TODO app with CDK Blocks and add one feature to it.

The key point is that everything from creation to verification is done in a cloud development environment (Claude Code's cloud environment) that has no AWS account or credentials.
At the end, I'll deploy the same code to real AWS from my local Mac and check whether it works as is.

What you'll build

To the react template's TODO app, I'll add a due date (dueAt) and a CronJob that checks for overdue items every minute.
Incomplete TODOs past their due date get an "Overdue" badge without needing to reload.

Screen where an Overdue badge is attached to a TODO past its due date

This screenshot was taken by running npm run dev in a cloud development environment with no AWS credentials.
Sign-in (equivalent to Cognito), saving TODOs (equivalent to DynamoDB), real-time sync between tabs (equivalent to API Gateway WebSocket), and the job that runs every minute (equivalent to EventBridge Scheduler) all run locally.

The code for the finished app is in the following repository.

https://github.com/ShuntaToda/cdk-blocks-todo-overdue

Why try it in a cloud development environment

Recently, even on real projects, I often develop using only Claude Code's cloud environment.
In this environment the AI agent runs commands by itself, so I don't want to hand over AWS credentials.
Because of that, I used to do the following preparation:

  1. Spin up dynamodb-local and a fake S3 in containers
  2. Write configuration in the app to switch the connection target between local and production
  3. For authentication, either build a fake login for local use myself, or borrow just the staging environment's Cognito and connect to it
  4. For parts that are hard to reproduce locally, such as scheduled execution, write mocks or deploy to AWS and check there

CDK Blocks has a local implementation for each Block, so this preparation is unnecessary.
The Auth Block also reproduces sign-up, confirmation code, and sign-in locally, so there's no need to build a fake login or borrow the staging Cognito.
Let's use a TODO app to check whether "it can be completed with just a cloud development environment".

Trying it out

Environment

  • Claude Code's cloud environment (a Linux container, no AWS credentials)
  • Node.js 22.23 / npm 10.9
  • Network access to the npm registry

CDK Blocks requires Node.js 22 or later and npm 10 or later.
I asked Claude Code to make the code changes, and had Claude Code take screenshots with Playwright to check the screen.

Creating the project

Use --template react to choose the React TODO app template.
Adding --yes creates it without prompts.

npm create @aws-cdk-blocks/blocks-app@latest todo-app -- --template react --yes
cd todo-app

There are 14 templates, and you can see the list with npm create @aws-cdk-blocks/blocks-app@latest -- --help.
The react template combines a Vite + React 19 frontend with the following Blocks.

Block Role On AWS
Auth Sign-up and sign-in with email address + password Amazon Cognito
KVStore Storing TODOs (separated per user, with optimistic locking) Amazon DynamoDB
Realtime Instantly reflect changes made in another tab API Gateway (WebSocket)

Of the generated files, you mainly touch just two.

  • cdk-blocks/index.ts … the backend (API, authentication, data). About 150 lines
  • src/App.tsx … the frontend

AGENTS.md is also generated, and it summarizes the CDK Blocks conventions for AI agents.
There's also a command to look up Block documentation in the terminal, like npm run docs KVStore, which gives agents such as Claude Code something to go on when you leave development to them.

Starting it locally

npm run dev
📝 Generating client code...
AWS CDK Blocks local server running on http://localhost:3000

Open http://localhost:3000, click "Sign In", then "Create Account" to sign up.

Sign-up screen

After signing up, you're asked for an email confirmation code.
Locally, no email is sent; the code is displayed in the terminal running npm run dev.

[auth] signUp code for demo@example.com: 184940

Confirmation code entry screen

Once you enter the code, you're signed in and can add TODOs.
Up to this point, I haven't used AWS credentials even once.

Adding a due date and a CronJob

Now for the main part. The features to add are the following two:

  1. Give TODOs a due date (dueAt)
  2. Every minute, look at all TODOs and set an overdue flag on incomplete TODOs past their due date

Overdue detection can also be done on the screen side, but keeping it as server-side state gives the same result from any screen, and it can later be used for email notifications and aggregation.

Add fields to the schema
The KVStore schema is written in Zod. Just add two optional fields.

cdk-blocks/index.ts
const todoSchema = z.object({
  userSub: z.string(),
  todoId: z.string(),
  title: z.string(),
  completed: z.boolean(),
  priority: z.number(),
  version: z.number(),
  createdAt: z.number(),
  dueAt: z.number().optional(),     // Due date (epoch ms). No due date if unset
  overdue: z.boolean().optional(),  // Set to true when the CronJob finds it overdue
});

Accept a due date in the create API
Add one argument to createTodo and put dueAt in the saved value.

cdk-blocks/index.ts
-  async createTodo(title: string, priority: number = 2) {
+  async createTodo(title: string, priority: number = 2, dueAt?: number) {
     const user = await auth.requireAuth(context);
     const todoId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
     const todo = {
       // ...
       createdAt: Date.now(),
+      dueAt,
     };

Check for overdue items with a CronJob
Add the CronJob Block to the import and define a job that runs every minute.
todos (KVStore), rt (Realtime), and todosChannel are already defined in the template, so write this after those definitions.

cdk-blocks/index.ts
import { ApiNamespace, ApiError, Scope, Auth, KVStore, Realtime, CronJob, KVStoreErrors, isBlocksError } from 'aws-cdk-blocks';

// ...

new CronJob(scope, 'overdue-check', {
  schedule: 'rate(1 minute)',
  handler: async () => {
    const now = Date.now();
    for await (const { value: todo } of todos.scan()) {
      if (todo.completed || todo.overdue || !todo.dueAt || todo.dueAt > now) continue;
      try {
        await todos.put(
          { userSub: todo.userSub, todoId: todo.todoId },
          { ...todo, overdue: true, version: todo.version + 1 },
          { ifFieldEquals: { version: todo.version } },
        );
      } catch (e) {
        // If the user updated it at the same time, revisit this TODO on the next run
        if (isBlocksError(e, KVStoreErrors.ConditionalCheckFailed)) continue;
        throw e;
      }
      await rt.publish('todos', todosChannel(todo.userSub), { action: 'updated' as const, todoId: todo.todoId });
      console.log(`[overdue-check] ${todo.todoId} is overdue`);
    }
  },
});

It reads all users' TODOs with todos.scan(), and writes back only the overdue ones with overdue: true.
As with the other APIs in the template, optimistic locking is applied via version.
If the user updated the item at the same time, it results in a ConditionalCheckFailedException, so only that TODO is skipped and revisited on the next run.
Finally, rt.publish notifies Realtime. This updates any open screens without a reload.

Note that scan reads the entire table every time.
For an app with a large number of TODOs, it's more appropriate to design an index so you can fetch only the unprocessed TODOs that have due dates, and narrow them down with query.
To focus on the procedure this time, I've left it as scan.

Add an input field and a badge to the frontend
In src/App.tsx, you only need to add a due date input field, a due date display, and the "Overdue" badge.

src/App.tsx
-type Todo = { todoId: string; title: string; completed: boolean; priority: number; version: number };
+type Todo = { todoId: string; title: string; completed: boolean; priority: number; version: number; dueAt?: number; overdue?: boolean };
 // ...
   const [newPriority, setNewPriority] = useState(2);
+  const [newDue, setNewDue] = useState('');
 // ...
-    if (!(await run(() => api.createTodo(newTitle.trim(), newPriority), 'Could not add todo'))) return;
+    if (!(await run(() => api.createTodo(newTitle.trim(), newPriority, newDue ? new Date(newDue).getTime() : undefined), 'Could not add todo'))) return;
     setNewTitle('');
+    setNewDue('');
 // ...
+        <input type="datetime-local" value={newDue} onChange={e => setNewDue(e.target.value)} aria-label="Due" />
         <button className="bb-button bb-button-primary" onClick={addTodo}>Add</button>
 // ...
             <span style={{ flex: 1 }}>{t.title}</span>
+            {t.dueAt && <small>{new Date(t.dueAt).toLocaleString()}</small>}
+            {t.overdue && !t.completed && <span style={{ color: '#fff', background: '#d13212', borderRadius: 4, padding: '0 6px', fontSize: '0.8em' }}>Overdue</span>}

The frontend calls the backend API directly with import { api } from 'cdk-blocks'.
The argument added to createTodo is also reflected in the frontend's types.
Type mistakes such as passing a string can be caught with npm run typecheck (since dueAt is optional, forgetting to pass it does not cause an error).

Verifying locally

Start it with npm run dev.
The startup log shows that the CronJob has been registered.

[CronJob:overdue-check] scheduled: rate(1 minute(s))

Next, add three TODOs from the screen.
One with a due date of tomorrow, one with a due date 5 minutes ago, and one with no due date.

Right after adding three TODOs

After waiting a minute, the CronJob log appears in the dev server's terminal.

[CronJob:overdue-check] triggered at 2026-11-30T22:03:01.196Z
[overdue-check] mx3tdfnd-zekb63 is overdue

Looking at the screen, the "Overdue" badge was attached only to the TODO whose due date was 5 minutes ago.
I did not reload.

After the CronJob ran, the TODO due 5 minutes ago has an Overdue badge

Local data is saved as JSON in .cdk-blocks/local/data/, so you can also check the contents directly.

.cdk-blocks/local/data/my-app-todos/store.json (excerpt)
{
  "todoId": "mx3tdfnd-zekb63",
  "title": "re:Inventの資料を整理する",
  "completed": false,
  "priority": 2,
  "version": 2,
  "dueAt": 1796075820000,
  "overdue": true
}

The local CronJob runs inside the dev server's process, and really does run every minute.
I didn't need to write an EventBridge mock for scheduled execution, or deploy and wait.

Checking the resources generated on AWS

The same new CronJob(...) definition becomes a different implementation locally and on AWS.

How the CronJob behaves locally and on AWS

cdk synth could also be run without credentials, so I checked the generated CloudFormation template while staying in the cloud development environment.
sandboxMode=true is a context that makes cdk-blocks/index.cdk.ts switch to the sandbox configuration.

npx cdk synth -q -c sandboxMode=true

Before adding the CronJob there were 115 resources; after adding it, there were 118.
The 115 consist of API Gateway (REST and WebSocket), Lambda, Cognito, DynamoDB, IAM, and so on.
The three that were added are as follows:

  • AWS::Scheduler::Schedule (the rate(1 minute) schedule)
  • AWS::IAM::Role (the role assumed by EventBridge Scheduler)
  • AWS::IAM::Policy (lambda:InvokeFunction to call the API's Lambda)

The schedule's target is the same Lambda function as the API. No Lambda dedicated to the CronJob is created.
There is one IAM role per backend, so for a second and later CronJobs, only the schedule is added.
The Block also builds the IAM wiring, so the app code contains only the schedule and the processing.

Deploying to AWS

Finally, I deploy the same code to AWS from my local Mac with npm run sandbox.
The sandbox is a CDK Blocks feature: a disposable verification environment prepared for each developer.
Under the hood it's a regular CDK deployment, so the Cognito, DynamoDB, and so on that get created are real AWS resources.
It differs from a production deployment with npm run deploy in the following ways:

  • The stack name includes the user name, so each developer gets a separate stack even in the same AWS account
  • Only the backend is deployed; the Hosting that serves the frontend (CloudFront, etc.) is not created
  • It keeps running, watches for code changes, and reflects them to the sandbox each time you save
  • It assumes you'll delete everything at once with npm run sandbox:destroy when finished, and it doesn't touch production stacks

From here on, AWS credentials and CDK bootstrap are required, so I deliberately switch from the cloud development environment to my local Mac, which has credentials.

npm run sandbox

The frontend starts at http://localhost:3000 on my machine and connects to the deployed backend.

On my machine, it took about 2 minutes 20 seconds from the start to "Sandbox deployed!".

🚀 Deploying to AWS...
   Synthesizing app...
⏳ [cdk synth + deploy] still running after 1m 00s — CloudFormation is converging
⏳ [cdk synth + deploy] still running after 2m 00s — CloudFormation is converging

✅ Sandbox deployed!
📡 API URL: https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/prod/cdk-blocks/api

👀 Starting CDK watch mode...
🌐 Starting local dev server (proxying to AWS)...

   Open http://localhost:3000

In the sandbox, Cognito sends a real confirmation email, so the confirmation code doesn't appear in the terminal as it does locally.
This time I created a verification user with the AWS CLI (--message-action SUPPRESS means no email is sent).

aws cognito-idp admin-create-user --user-pool-id <ユーザープールID> \
  --username demo@example.com --message-action SUPPRESS
aws cognito-idp admin-set-user-password --user-pool-id <ユーザープールID> \
  --username demo@example.com --password '<パスワード>' --permanent

When I added three TODOs with the same steps as locally, the "Overdue" badge was attached only to the TODO due 5 minutes ago, within a minute.

Screen where Overdue is attached in the sandbox too

Let's check the AWS side too.
A rate(1 minute) schedule had been created in EventBridge Scheduler, and its target was the same Lambda function as the API.
The Lambda's CloudWatch Logs show the same log as locally.

INFO  [overdue-check] mx3u1c7r-y70sfc is overdue

Looking at the DynamoDB table, only the relevant TODO had overdue: true and version: 2.
I didn't change a single line of the app code from what I verified locally.

When you've finished checking, delete the sandbox.
The CronJob keeps running every minute until it's deleted, so be careful.

npm run sandbox:destroy

The deletion finished in about 1 minute, and the stack became DELETE_COMPLETE.
The Cognito user pool, DynamoDB table, EventBridge Scheduler schedule, and so on were also gone.
However, a few CloudWatch Logs log groups created by the Lambda for CDK custom resources remain, so delete them manually if they bother you.

What I learned from using it

You can go from building to running to verifying without AWS credentials
Authentication, data, real-time notifications, and scheduled execution could all be verified entirely within the cloud development environment.
Being able to repeat implementation and verification without handing AWS credentials to the AI agent is a big help.

No fake login or staging Cognito needed
Until now, I sometimes had to build a fake login for local use myself, or connect only the authentication to the staging environment's Cognito.
The Auth Block works locally from sign-up through confirmation code to sign-in, so there's no need to implement a fake login, nor to connect from the cloud development environment to staging or handle its credentials.

Add just one Block and it works both locally and on AWS
When I added the CronJob, all I wrote was the schedule and the processing.
Locally it actually runs every minute, and on AWS even the EventBridge Scheduler and IAM wiring are generated.

Be aware of what isn't reproduced locally
The local CronJob doesn't retry on failure, but on AWS it is retried.
Also, AWS-side behavior such as the limit on confirmation emails sent by Cognito has to be checked in the sandbox.
Note too that the sandbox's watch updates Lambda via hotswap, so a warning about drift from CloudFormation appears.

Summary

I built a TODO app with the AWS CDK Blocks react template and added a due date and an overdue check via a CronJob.
Everything from creation to verification could be done in a cloud development environment without AWS credentials.
I was also able to confirm that the same code works when deployed to AWS in the sandbox.

The app I built this time is in the following repository. You can see the changes from the template all together in the second commit.

https://github.com/ShuntaToda/cdk-blocks-todo-overdue

If you've been building local environments with dynamodb-local and the like, or want to leave development to an AI agent in the cloud, please give it a try!

References

https://dev.classmethod.jp/articles/aws-cdk-blocks-overview/

https://docs.aws.amazon.com/cdk/blocks/devguide/what-is-blocks.html

https://github.com/aws/cdk-blocks

https://github.com/ShuntaToda/cdk-blocks-todo-overdue


AWS re:Invent 2026まとめ情報

クラスメソッドは2026/11/30〜12/4にラスベガスで開催されるAWSカンファレンスイベント「re:Invent」を今年も特集しました。ぜひ一度ご覧ください。 re:Invent 2026ポータルサイトを見るAWS re:Invent公式サイトはこちら

Share this article