INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

Topic lessonTopic: AWS CDK: source and synthesis

AWS CDK synth explained: constructs and CloudFormation

AWS CDK describes infrastructure in program code; synthesis produces CloudFormation templates and deployment artifacts. Successful synthesis and successful deployment are different outcomes. Read a short example through containment, references and change review.

What you will learn

Read the relationship between apps, stacks and constructs, and distinguish reviewing synthesized artifacts from applying them to AWS.

Prerequisite

Knowing CloudFormation Resources, logical IDs and Ref helps. Detailed TypeScript knowledge is unnecessary. Read the example here; this page does not execute CDK or access AWS.

From code to assembly, then deployment

Separate artifacts from deployment outcomes
StageWhat it handlesWhat to review
DescribeInfrastructure declared in program codeResources, references, conditions and defaults.
SynthesizeA cloud assembly: CloudFormation templates, assets and related artifactsGenerated resources and properties, plus required deployment artifacts.
Deploy and verifyThe target AWS environment and actual functionsImpact, execution results, then traffic and application behavior.

A cloud assembly can contain more than templates. File or image assets can be part of the deployment. Review generated infrastructure as well as the readability of its source code.

Apps, stacks and constructs organize infrastructure

Read containment: arrows are not network traffic
Read containment: arrows are not network traffic1: App — Contains — ReportStack. 2: ReportStack — Contains — ReportNetwork. 3: ReportStack — Contains — ReportGroup123AppReportStackReportNetworkReportGroupRead containment: arrows are not network traffic1: App — Contains — ReportStack. 2: ReportStack — Contains — ReportNetwork. 3: ReportStack — Contains — ReportGroup123AppReportStackReportNetworkReportGroup
  1. App → ReportStackContains
  2. ReportStack → ReportNetworkContains
  3. ReportStack → ReportGroupContains
App
Application assembling the model
ReportStack
The stack in this example
ReportNetwork
L1 declaring a VPC
ReportGroup
L1 declaring a security group

A construct is a building block, a stack is the unit represented by a CloudFormation stack, and an app assembles them. The diagram does not show a security group sending traffic to a VPC. Read resource references in the properties below.

Fixed example: pass a VPC reference to a security group

TypeScript reading example, not an executed synthesisScroll horizontally to read long lines. Use arrow keys in the code area.
import { App, Stack, aws_ec2 as ec2 } from 'aws-cdk-lib';

const app = new App();
const stack = new Stack(app, 'ReportStack');
const network = new ec2.CfnVPC(stack, 'ReportNetwork', {
  cidrBlock: '10.20.0.0/16'
});
new ec2.CfnSecurityGroup(stack, 'ReportGroup', {
  groupDescription: 'Illustrative group',
  vpcId: network.ref
});
app.synth();
Distinguish identifiers from resource references
CodeMeaning
new Stack(app, 'ReportStack')Place a stack inside the app.
new ec2.CfnVPC(stack, 'ReportNetwork', ...)Place an L1 VPC construct inside the stack.
vpcId: network.refPass a VPC Ref for CloudFormation to resolve.
app.synth()Generate artifacts from the app; this is not evidence of successful AWS deployment.

Separate abstraction levels from resource identities

Read abstraction levels
LevelWhat it expressesReview focus
L1A low-level construct directly representing a CloudFormation resource, commonly named Cfn…Review required properties.
L2A higher-level API with helper behaviorInspect generated defaults and permissions.
L3 / patternA composition of building blocksInspect what the concise source actually creates.
Different identifiers serve different roles
IdentifierRole
Construct IDIdentifies a construct within its scope.
CloudFormation logical IDTracks a resource in the template; its construct path contributes to generation.
Physical resource identifierAn ID or name of a created resource, not necessarily the code identifier.

Moving constructs or changing IDs can alter logical IDs and lead to resource replacement. Code cleanup is not automatically infrastructure-neutral. Inspect generated artifacts and differences for identity or replacement changes. Compare identifiers against the actual generated artifacts.

Synthesis success is a limited claim

Synthesis runs application code. Context lookup and asset preparation can involve AWS queries or additional processing. Do not assume synthesis is unconditionally offline or harmless.

  1. Review the app and its building blocks, including execution and lookup conditions.
  2. Inspect templates and assets for changes, permissions, replacements and deletions.
  3. Align environment, permissions and approval, then deploy and verify actual functions.

Check your understanding

Choose an option to see the result and explanation.

Synthesis succeeded. Has AWS deployment also completed?
Read the answer and reason

Answer: No; inspect deployment results separately · Synthesis success is not evidence of resource creation or update in the target.

What does App → Stack → Construct represent?
Read the answer and reason

Answer: Containment in an infrastructure model · It organizes stacks and their building blocks, not a packet route.

What does network.ref pass to the security group?
Read the answer and reason

Answer: A VPC reference resolved by CloudFormation · The example passes a VPC Ref into vpcId.

Can code cleanup skip resource identity review?
Read the answer and reason

Answer: No; review logical IDs and differences · Review prevents overlooking unintended replacement or deletion.

Is synthesis safe to run without reviewing app code?
Read the answer and reason

Answer: No; inspect code execution and lookup conditions · Synthesis runs app code and may involve environment or asset processing.

Does one high-level construct always mean one physical resource?
Read the answer and reason

Answer: No; inspect generated infrastructure · Inspect what higher-level building blocks or patterns assemble.

Check, then explain in your own words

  1. Separate apps, stacks and constructs in the containment diagram.
  2. Read scopes and Ref in the fixed code.
  3. Use the questions and review to explain checks after synthesis.
Check your understanding: What should a CDK review inspect besides source code?

Inspect generated templates and assets, references and logical IDs, permissions and replacement/deletion differences, the target environment and post-deployment functions.

Readable source, generated artifacts, deployment outcomes and actual functions are separate review targets.

Sources and conditions checked

The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.