A practical example that includes a Lambda function and DynamoDB table.
This stack includes the following resources:
- DynamoDB Table: Table for storing items
- Lambda Function: Simple function with Python 3.12 runtime
- IAM Role: Lambda execution role with DynamoDB access permissions
- IAM Policy: Read/write permissions for the DynamoDB table
- Lambda Asset Publishing: Code from
lambda/directory is uploaded to S3 - Ref in Environment Variables: DynamoDB table name is referenced in the
TABLE_NAMEenvironment variable - Resource Dependencies: Lambda → DynamoDB → IAM Role dependency chain
- Automatic IAM Policy Generation: Policy creation via
grantReadWriteData() - Fn::GetAtt: Retrieve Lambda ARN and DynamoDB ARN in outputs
# Install packages
vp install
# Deploy with cdkd
node ../../../dist/cli.js deploy \
--app "node bin/app.ts" \
--state-bucket <your-state-bucket> \
--region us-east-1 \
--verbose- Lambda assets are correctly published to S3
- DynamoDB table is created
- Lambda function is created with the correct role attached
- Environment variable
TABLE_NAMEis set to the table name - IAM Policy is correctly created and attached to Lambda execution role
- Outputs are correctly resolved (function name, ARN, etc.)
node ../../../dist/cli.js destroy \
--state-bucket <your-state-bucket> \
--stack LambdaStack \
--region us-east-1 \
--force