AWS CDK apps are effectively only a definition of your infrastructure using code. When CDK apps are executed, they produce (or “synthesize", in CDK parlance) an AWS CloudFormation template for each stack defined in your application.
To synthesize a CDK app, use the
cdk synth command. Let's check out the
template synthesized from the sample app. Because our app includes two stacks
we need to tell the
cdk synth command which stack we want to synthesize.
You can get a list of available stacks:
The CDK CLI requires you to be in the same directory
cdk.json file. If you have changed directories in your terminal,
please navigate back now.
$ cdk ls cdkworkshop $
We can then synthesize one of the stacks:
$ cdk synth
This will output the following CloudFormation template:
Resources: CdkworkshopQueue18864164: Type: AWS::SQS::Queue Properties: VisibilityTimeout: 300 Metadata: aws:cdk:path: cdkworkshop/CdkworkshopQueue/Resource CdkworkshopQueuePolicy78D5BF45: Type: AWS::SQS::QueuePolicy Properties: PolicyDocument: Statement: - Action: sqs:SendMessage Condition: ArnEquals: aws:SourceArn: Ref: CdkworkshopTopic58CFDD3D Effect: Allow Principal: Service: sns.amazonaws.com Resource: Fn::GetAtt: - CdkworkshopQueue18864164 - Arn Version: "2012-10-17" Queues: - Ref: CdkworkshopQueue18864164 Metadata: aws:cdk:path: cdkworkshop/CdkworkshopQueue/Policy/Resource CdkworkshopQueuecdkworkshopCdkworkshopTopic7642CC2FCF70B637: Type: AWS::SNS::Subscription Properties: Protocol: sqs TopicArn: Ref: CdkworkshopTopic58CFDD3D Endpoint: Fn::GetAtt: - CdkworkshopQueue18864164 - Arn Metadata: aws:cdk:path: cdkworkshop/CdkworkshopQueue/cdkworkshopCdkworkshopTopic7642CC2F/Resource CdkworkshopTopic58CFDD3D: Type: AWS::SNS::Topic Metadata: aws:cdk:path: cdkworkshop/CdkworkshopTopic/Resource CDKMetadata: Type: AWS::CDK::Metadata Properties: Modules: aws-cdk=1.18.0,jsii-runtime=Python/3.7.3
As you can see, this template includes a bunch of resources:
The AWS::CDK::Metadata resource is automatically added by the toolkit to every stack. It is used by the AWS CDK team for analytics and to allow us to identify versions with security issues. See Version Reporting in the AWS CDK User Guide for more details. We will omit the metadata resource in diff views for the rest of this workshop