AWS Cloud Development Kit (CDK) - Developer Guide

Developer Guide

AWS Cloud Development Kit (AWS CDK) v2

Version 2

Copyright ? 2024 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

AWS Cloud Development Kit (AWS CDK) v2

Developer Guide

AWS Cloud Development Kit (AWS CDK) v2: Developer Guide

Copyright ? 2024 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.

AWS Cloud Development Kit (AWS CDK) v2

Table of Contents

Developer Guide

What is the AWS CDK? .................................................................................................................... 1 Benefits of the AWS CDK ........................................................................................................................... 2 Example of the AWS CDK ........................................................................................................................... 5 AWS CDK features ...................................................................................................................................... 10 The AWS CDK GitHub repository ....................................................................................................... 10 The AWS CDK API reference ............................................................................................................... 10 The Construct Programming Model .................................................................................................. 10 The Construct Hub ............................................................................................................................... 10 Next steps .................................................................................................................................................... 11 Learn more .................................................................................................................................................. 11

CDK core concepts ......................................................................................................................... 12 AWS CDK and IaC ....................................................................................................................................... 12 AWS CDK and AWS CloudFormation ..................................................................................................... 12 AWS CDK and abstractions ...................................................................................................................... 13 Learn more about core AWS CDK concepts .......................................................................................... 13 Interacting with the AWS CDK ........................................................................................................... 13 Developing with the AWS CDK .......................................................................................................... 13 Deploying with the AWS CDK ............................................................................................................ 13 Learn more ............................................................................................................................................. 14 Languages .................................................................................................................................................... 14 Projects ......................................................................................................................................................... 16 Universal files and folders .................................................................................................................. 17 Language-specific files and folders .................................................................................................. 17 Apps .............................................................................................................................................................. 30 Defining apps ......................................................................................................................................... 30 The construct tree ................................................................................................................................ 32 The app lifecycle ................................................................................................................................... 33 Stacks ............................................................................................................................................................ 37 Defining stacks ...................................................................................................................................... 37 Working with stacks ............................................................................................................................. 44 Constructs .................................................................................................................................................... 51 The Construct Library .......................................................................................................................... 52 Defining constructs ............................................................................................................................... 55 Working with constructs ..................................................................................................................... 64

Version 2 iii

AWS Cloud Development Kit (AWS CDK) v2

Developer Guide

Working with third-party constructs ................................................................................................ 70 Learn more ............................................................................................................................................. 79 Environments .............................................................................................................................................. 79 Learn more ............................................................................................................................................. 81 Bootstrapping .............................................................................................................................................. 81 What is bootstrapping? ....................................................................................................................... 81 How does bootstrapping work? ......................................................................................................... 82 Learn more ............................................................................................................................................. 82 Resources ...................................................................................................................................................... 82 Configuring resources using constructs ........................................................................................... 83 Referencing resources .......................................................................................................................... 86 Resource physical names ..................................................................................................................... 95 Passing unique resource identifiers .................................................................................................. 97 Granting permissions between resources ...................................................................................... 100 Resource metrics and alarms ........................................................................................................... 103 Network traffic .................................................................................................................................... 106 Event handling .................................................................................................................................... 110 Removal policies ................................................................................................................................. 111 Identifiers ................................................................................................................................................... 116 Construct IDs ....................................................................................................................................... 116 Paths ...................................................................................................................................................... 119 Unique IDs ............................................................................................................................................ 120 Logical IDs ............................................................................................................................................ 122 Tokens ......................................................................................................................................................... 122 Tokens and token encodings ............................................................................................................ 124 String-encoded tokens ...................................................................................................................... 126 List-encoded tokens ........................................................................................................................... 128 Number-encoded tokens ................................................................................................................... 128 Lazy values ........................................................................................................................................... 128 Converting to JSON ........................................................................................................................... 131 Parameters ................................................................................................................................................. 132 About parameters ............................................................................................................................... 132 Defining parameters .......................................................................................................................... 133 Using parameters ............................................................................................................................... 135 Deploying with parameters .............................................................................................................. 137 Tagging ....................................................................................................................................................... 140

Version 2 iv

AWS Cloud Development Kit (AWS CDK) v2

Developer Guide

Using tags ............................................................................................................................................ 141 Tag priorities ........................................................................................................................................ 143 Optional properties ............................................................................................................................ 144 Example ................................................................................................................................................ 147 Tagging single constructs ................................................................................................................. 151 Assets .......................................................................................................................................................... 154 Assets in detail .................................................................................................................................... 154 Asset types ........................................................................................................................................... 155 Amazon S3 assets ............................................................................................................................... 155 Docker image assets .......................................................................................................................... 168 AWS CloudFormation resource metadata ..................................................................................... 179 Permissions ................................................................................................................................................ 179 Principals .............................................................................................................................................. 180 Grants .................................................................................................................................................... 180 Roles ...................................................................................................................................................... 183 Resource policies ................................................................................................................................. 189 Using external IAM objects ............................................................................................................... 190 Context ....................................................................................................................................................... 191 Sources of context values ................................................................................................................. 192 Context methods ................................................................................................................................ 193 Viewing and managing context ....................................................................................................... 194 AWS CDK Toolkit --context flag ................................................................................................. 195 Example ................................................................................................................................................ 196 Feature flags ............................................................................................................................................. 200 Reverting to v1 behavior .................................................................................................................. 201 Aspects ....................................................................................................................................................... 202 Aspects in detail ................................................................................................................................. 203 Example ................................................................................................................................................ 204 Getting started ............................................................................................................................ 208 Prerequisites .............................................................................................................................................. 208 Step 1: Create an AWS account and administrative user ................................................................ 208 Step 2: Determine your method of managing users ........................................................................ 208 Step 3: Install the AWS CLI ................................................................................................................... 209 Step 4: Install Node.js and programming language prerequisites ................................................. 209 Step 5: Install the AWS CDK CLI ........................................................................................................... 211 Step 6: Configure security credentials for the CDK CLI ................................................................... 212

Version 2 v

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download