Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

The CDK Deploy That Quietly Deleted Our Order History Table at 2 AM

Build a production-safe serverless CRUD API with Lambda, API Gateway and DynamoDB using AWS CDK v2.

MCB Editorial

Tech Buzz Daily Desk · 10 min read ·

New story
Narrated by Study Buddy Narration
Voiceover Engine • Interactive Audio Sync
0:0010:00

Learning Objectives & Key Takeaways

0 / 4 Completed
Architecture Ready
100%
What you will learn
  1. Changing a DynamoDB partition or sort key forces CloudFormation to replace the table, not update it.
  2. HTTP API Lambda integrations add one IAM permission statement per route by default, which can exceed the function policy limit.
  3. Grant DynamoDB access with grantReadWriteData instead of hand-written IAM policies to stay least privilege.
  4. Always run cdk diff before cdk deploy so a schema change never surprises you again.
  5. A public API Gateway endpoint from a tutorial stack is a real liability until authorization is added.

A Flash Sale, a Schema Tweak, and a Table That Vanished

The order history service for a mid-sized e-commerce platform was a clean little CDK stack: one Lambda function, one REST API, one DynamoDB table keyed on orderId. During a post-Diwali flash sale, the team decided customers also needed to query orders by customer email, so an engineer added a sortKey to the existing table definition and ran cdk deploy without reading the plan first.

CloudFormation does not know how to add a sort key to a live table in place. When a partition key or sort key changes, DynamoDB tables are not updated, they are replaced, which means the old table is deleted and a new empty one is created under the same logical ID. Because the table had no explicit removal policy set, the default behavior kicked in and years of order rows disappeared in the time it took the deploy to finish.

In the rest of this story
  1. What You Will Build Today
  2. Setting Up and Deploying the Stack
  3. The Complete Stack and Handler
  4. Permission Pitfalls Nobody Warns You About
  5. Testing, Observing, and Tearing Down Safely
1 code example · 10 min read in full
Member-only story

Checking your membership…

Members read every Tech Buzz story in full, with code examples, audio and the discussion, plus every course, quiz and interview set in the Learning Dashboard.

0

Written by

MCB Editorial

Tech Buzz Daily Desk. Contributing deep-dive engineering architectures, cloud paradigms, and system design insights to Master Class Buddy.