AWS CDK enables defining cloud infrastructure in TypeScript, Python, or Java using a library of composable constructs. Understanding the construct hierarchy, synthesis process, and grant methods is essential for CDK practitioners.
0 / 5 completed
1 / 5
What are the three levels of CDK Constructs (L1, L2, L3) and what distinguishes them?
L1 (Cfn* classes) map 1:1 to CloudFormation resources with no abstraction. L2 constructs wrap L1 with sensible defaults, helper methods, and IAM/security conveniences. L3 (patterns) are opinionated multi-resource constructs representing complete architectural patterns (e.g., ApplicationLoadBalancedFargateService creates ALB + ECS service + security groups together).
2 / 5
A developer runs cdk synth. What does this command produce?
cdk synth executes the CDK app code and synthesizes CloudFormation templates into the cdk.out/ directory. This is useful for reviewing generated CloudFormation before deploying, running in CI to validate changes, or using the templates with other deployment tools. cdk deploy implicitly runs synth before deploying.
3 / 5
What is the purpose of cdk.json in a CDK project?
cdk.json is the CDK project configuration file. Key fields include "app" (the command to run the CDK app, e.g., "npx ts-node bin/app.ts"), "context" (key-value pairs passed to the app), and "featureFlags" (opt-in/opt-out of breaking behavior changes). The CDK CLI reads this file to know how to execute the app.
4 / 5
A CDK L2 construct call grants permissions using bucket.grantRead(lambdaFn). What does this method do under the hood?
CDK's grant methods (like grantRead(), grantWrite()) are a key L2 feature. They add the appropriate IAM policy statement to the grantee's IAM principal (e.g., Lambda execution role). CDK knows the minimum required permissions for the operation and handles the ARN construction, eliminating common IAM misconfiguration errors.
5 / 5
When should a CDK developer call app.synth() explicitly versus relying on automatic synthesis?
CDK automatically calls app.synth() when the process exits if using the standard App/Stack pattern. Explicit app.synth() is needed in unit tests (to get the CloudFormation template for assertions) or when programmatically accessing the synthesis output (e.g., SynthesisResult). In normal CLI usage, cdk synth/deploy triggers synthesis automatically.