SlideShare a Scribd company logo
AWS CDK​ - Introduction & Beyond
Jason Butz
Solution Architect & Practice Lead @ DMI
AWS Community Builder & AWS Certification SME
dminc.com jasonbutz.info @jbutz@hachyderm.io
The Situation
Infrastructure as Code
• “A fundamental principle of DevOps is to treat infrastructure the
same way developers treat code” – AWS
• All infrastructure defined by code and stored in version control
Tools
AWS
• CloudFormation
• Serverless Application Model
(SAM)
• Cloud Development Kit (CDK)
Non-AWS
• Puppet
• Chef
• Ansible
• Terraform
• Serverless Framework
• Pulumi
• ...
AWS Cloud
Region
Amazon CloudFront
Website Bucket
Logs Bucket Logs Bucket
Image Source: AWS CDK Documentation
Construct Scope ID
Properties
Reference: Use generated resource names, not physical names
CDK Tip: Don’t Name Resources
Constructs
• L1: Low-level
• L2: Intent-based
• L3: Patterns
AWS Solutions Constructs
• AWS created constructs for common patterns that follow best
practices
Reference: AWS Solutions Constructs
CDK - Beyond
AWS has a detailed ”Best
Practices” document for the
CDK, it’s worth a read
Don't Put It All In the Constructor!
Use constructs and methods to
break up the code
One App – Multiple Stacks
• More than nested stacks
• Multiple regions, multiple accounts
Example: Deployment Environments
Example: jasonbutz.info
CDN Stack (us-east-1)
CloudFront
Distribution
ACM Certificate
Primary Stack (us-east-2)
S3 Replication
Amazon S3 Bucket
Secondary Stack (us-west-2)
Amazon S3 Bucket
Automated Testing
• Focus on:
• Important constructs
• Critical infrastructure
• Snapshotting
Review
• Define cloud resources using constructs and OOP
• Use AWS Solution Constructs to build common patterns
• Decompose your stack with constructs
• Use multiple stacks within the same CDK app
• Use automated testing, when it makes sense
Please Provide Feedback!
Thank You
• AWS CDK v2 - What is the AWS CDK?
• AWS CDK Workshop
• AWS CDK v2 - Best Practices
• AWS Solutions Constructs
• Construct Hub
• AWS CDKv2 - CDK Pipelines
• CDK Pipelines for GitHub Workflows

More Related Content

Similar to AWS CDK​ - Introduction and Beyond - Indy.Code() 2023

Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda
Outlyer
 
LaunchingYourAppTheAmazonWay_SFStartupDay
LaunchingYourAppTheAmazonWay_SFStartupDayLaunchingYourAppTheAmazonWay_SFStartupDay
LaunchingYourAppTheAmazonWay_SFStartupDay
Amazon Web Services
 
DevOps on AWS - Accelerating Software Delivery
DevOps on AWS - Accelerating Software DeliveryDevOps on AWS - Accelerating Software Delivery
DevOps on AWS - Accelerating Software Delivery
Amazon Web Services
 
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Amazon Web Services
 
Business Agility: Taking an App Global (at Speed) - Session Sponsored by ITOC
Business Agility: Taking an App Global (at Speed) - Session Sponsored by ITOCBusiness Agility: Taking an App Global (at Speed) - Session Sponsored by ITOC
Business Agility: Taking an App Global (at Speed) - Session Sponsored by ITOC
Amazon Web Services
 
Aws User Group Singapore Presentation Oct-21-2020
Aws User Group Singapore Presentation Oct-21-2020Aws User Group Singapore Presentation Oct-21-2020
Aws User Group Singapore Presentation Oct-21-2020
Varun Manik
 
Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用
Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用
Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用
Amazon Web Services
 
Fin jaws 202103
Fin jaws 202103Fin jaws 202103
Fin jaws 202103
Yuki Yoshida
 
Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...
Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...
Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...
Amazon Web Services
 
Journey Towards Scaling Your Application to Million Users
Journey Towards Scaling Your Application to Million UsersJourney Towards Scaling Your Application to Million Users
Journey Towards Scaling Your Application to Million Users
Adrian Hornsby
 
AWS Startup Day Bangalore: Being Well-Architected in the Cloud
AWS Startup Day Bangalore: Being Well-Architected in the CloudAWS Startup Day Bangalore: Being Well-Architected in the Cloud
AWS Startup Day Bangalore: Being Well-Architected in the Cloud
Adrian Hornsby
 
Eliminate repetitive work by using AWS Serverless Application Repository
Eliminate repetitive work by using AWS Serverless Application RepositoryEliminate repetitive work by using AWS Serverless Application Repository
Eliminate repetitive work by using AWS Serverless Application Repository
Igor Soroka
 
Build an app on aws for your first 10 million users (2)
Build an app on aws for your first 10 million users (2)Build an app on aws for your first 10 million users (2)
Build an app on aws for your first 10 million users (2)
AWS Vietnam Community
 
How Serverless Computing Enables Microservices and Micropayment
How Serverless Computing Enables Microservices and Micropayment  How Serverless Computing Enables Microservices and Micropayment
How Serverless Computing Enables Microservices and Micropayment
Mitoc Group
 
Building A Dynamic Website - 31st Jan 2015
Building A Dynamic Website - 31st Jan 2015Building A Dynamic Website - 31st Jan 2015
Building A Dynamic Website - 31st Jan 2015
Jhalak Modi
 
Raleigh DevDay 2017: Building CICD pipelines for serverless applications
Raleigh DevDay 2017: Building CICD pipelines for serverless applicationsRaleigh DevDay 2017: Building CICD pipelines for serverless applications
Raleigh DevDay 2017: Building CICD pipelines for serverless applications
Amazon Web Services
 
DevOps for Serverless Computing with Demo
DevOps for Serverless Computing with DemoDevOps for Serverless Computing with Demo
DevOps for Serverless Computing with Demo
Amazon Web Services
 
Serverless Culture
Serverless CultureServerless Culture
Serverless Culture
AWS User Group Bengaluru
 
Announcing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck TalksAnnouncing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck Talks
Amazon Web Services
 
Building Scalable Web Applications using Microservices Architecture and Serve...
Building Scalable Web Applications using Microservices Architecture and Serve...Building Scalable Web Applications using Microservices Architecture and Serve...
Building Scalable Web Applications using Microservices Architecture and Serve...
Mitoc Group
 

Similar to AWS CDK​ - Introduction and Beyond - Indy.Code() 2023 (20)

Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda
 
LaunchingYourAppTheAmazonWay_SFStartupDay
LaunchingYourAppTheAmazonWay_SFStartupDayLaunchingYourAppTheAmazonWay_SFStartupDay
LaunchingYourAppTheAmazonWay_SFStartupDay
 
DevOps on AWS - Accelerating Software Delivery
DevOps on AWS - Accelerating Software DeliveryDevOps on AWS - Accelerating Software Delivery
DevOps on AWS - Accelerating Software Delivery
 
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
 
Business Agility: Taking an App Global (at Speed) - Session Sponsored by ITOC
Business Agility: Taking an App Global (at Speed) - Session Sponsored by ITOCBusiness Agility: Taking an App Global (at Speed) - Session Sponsored by ITOC
Business Agility: Taking an App Global (at Speed) - Session Sponsored by ITOC
 
Aws User Group Singapore Presentation Oct-21-2020
Aws User Group Singapore Presentation Oct-21-2020Aws User Group Singapore Presentation Oct-21-2020
Aws User Group Singapore Presentation Oct-21-2020
 
Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用
Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用
Track 4 Session 4_ MAD02 MAD 04 如何藉由 CICD 流程管理容器化和無伺服器應用
 
Fin jaws 202103
Fin jaws 202103Fin jaws 202103
Fin jaws 202103
 
Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...
Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...
Infrastructure Is Code with the AWS Cloud Development Kit (DEV372) - AWS re:I...
 
Journey Towards Scaling Your Application to Million Users
Journey Towards Scaling Your Application to Million UsersJourney Towards Scaling Your Application to Million Users
Journey Towards Scaling Your Application to Million Users
 
AWS Startup Day Bangalore: Being Well-Architected in the Cloud
AWS Startup Day Bangalore: Being Well-Architected in the CloudAWS Startup Day Bangalore: Being Well-Architected in the Cloud
AWS Startup Day Bangalore: Being Well-Architected in the Cloud
 
Eliminate repetitive work by using AWS Serverless Application Repository
Eliminate repetitive work by using AWS Serverless Application RepositoryEliminate repetitive work by using AWS Serverless Application Repository
Eliminate repetitive work by using AWS Serverless Application Repository
 
Build an app on aws for your first 10 million users (2)
Build an app on aws for your first 10 million users (2)Build an app on aws for your first 10 million users (2)
Build an app on aws for your first 10 million users (2)
 
How Serverless Computing Enables Microservices and Micropayment
How Serverless Computing Enables Microservices and Micropayment  How Serverless Computing Enables Microservices and Micropayment
How Serverless Computing Enables Microservices and Micropayment
 
Building A Dynamic Website - 31st Jan 2015
Building A Dynamic Website - 31st Jan 2015Building A Dynamic Website - 31st Jan 2015
Building A Dynamic Website - 31st Jan 2015
 
Raleigh DevDay 2017: Building CICD pipelines for serverless applications
Raleigh DevDay 2017: Building CICD pipelines for serverless applicationsRaleigh DevDay 2017: Building CICD pipelines for serverless applications
Raleigh DevDay 2017: Building CICD pipelines for serverless applications
 
DevOps for Serverless Computing with Demo
DevOps for Serverless Computing with DemoDevOps for Serverless Computing with Demo
DevOps for Serverless Computing with Demo
 
Serverless Culture
Serverless CultureServerless Culture
Serverless Culture
 
Announcing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck TalksAnnouncing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck Talks
 
Building Scalable Web Applications using Microservices Architecture and Serve...
Building Scalable Web Applications using Microservices Architecture and Serve...Building Scalable Web Applications using Microservices Architecture and Serve...
Building Scalable Web Applications using Microservices Architecture and Serve...
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 

AWS CDK​ - Introduction and Beyond - Indy.Code() 2023

Editor's Notes

  1. Introduce talk and self Solution Architect and Practice Lead at DMI AWS Community Builder since February Certification SME, focusing on the Dev Assoc exam All opinions are my own and do not necessarily reflect those of my employer, AWS, or anybody else This talk is largely based around what I have seen from newer CDK users and trying to move them towards better usage of the CDK Icon Source: Font Awesome (https://fontawesome.com/license/free)
  2. Let’s say I’ve got a lot of thoughts and opinions (CLICK) I want to write those all down (CLICK) And I of course don’t want to keep those to myself, I want them on the internet (CLICK) So I want a website, and I want to make and deploy it myself because using some service undermines my “dev cred” and also undermines the story I’m using in this talk I don’t want to configure and maintain everything by a bunch of clicking, I want automation. I want -> IaC
  3. IaC is key concept within DevOps Infra defined via config or code and stored in version control Automated deployments Hopefully repeatable builds Sources “A fundamental principle of DevOps is to treat infrastructure the same way developers treat code” - https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html
  4. Numerous IaC Tools AWS has several, all building on CloudFormation AWS’s IaC service, deploys code and handles rollback on errors Limited number of tools also mentioned here
  5. CloudFormation Template Very basic partial example of an API with single endpoint YAML or JSON
  6. AWS SAM Similar situation, an API with one endpoint YAML or JSON
  7. CDK Same situation, API with a single endpoint TypeScript, using objects, with IntelliSense, same linting tools AWS CDK supports TypeScript, JavaScript, Python, Java, C#/.NET, and Go
  8. This is my goal, a simple website on AWS for static assets CloudFront (CDN) returning resources from an S3 Bucket Two S3 Buckets for log files If you have a question about why the two buckets for logs, hang on to that Next: Let’s talk about some key concepts with the CDK before we get much further
  9. CDK Concept: Construct Construct = “Cloud Component,” one or more resources and configuration Single or Multiple resources, an SQS Queue, or an entire API Stacks contain one or more constructs and directly map to CloudFormation stacks Apps contain one or more stacks CDK App is transpiled to a CloudFormation Template then deployed using CloudFormation
  10. Example of using a Construct This case creating an encrypted S3 Bucket Construct = what we’re defining Scope = what contains this construct, must always be a construct, Stacks and Apps are special constructs ID = Identifier unique within the scope for the construct. Very similar concept to Logical ID if you know CloudFormation Props: Properties for the Construct. Here it's defining a name for our S3 bucket and turning on the encryption Best Practices for CFN apply, [NEXT SLIDE TIP]
  11. Best Practice / Tip – CFN/SAM/CDK Don’t name your resources unless you REALLY need to CFN generates a unique name for you Reference: https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html#best-practices-apps-names
  12. L1: Low-level, nearly identical to CloudFormation template resource Can be used as an escape hatch to provision resources not supported by the CDK L2: Intent-based, wraps one or more resources and includes configuration and permission aspects The majority of constructs you’ll end up using L3: Patterns The solution constructs as well as many other custom constructs Create your own as your apps grow Image Source: https://pixabay.com/vectors/building-blocks-tetris-3d-blocks-2026721/
  13. Talked about what the CDK is, but not how to deploy it Node.js CLI tool Bootstrap account and regions CLI tool can initialize and deploy your app CDK resources can live alongside the rest of your app
  14. Initialize an app in a directory and you’ll get a structure like this Bin directory has where you define your CDK App and how the Stacks are used Lib directory has your stack file and other constructs
  15. AWS created constructs for common patterns and built them using best practices Numerous common patterns, including connecting CloudFront to S3 (CDN to storage for static assets) Available in TypeScript/JavaScript, Java, and Python for sure. Maybe others
  16. This shows the Stack file with the comments removed and our solution construct added Deploying this, we get: CloudFront Distribution (CDN) S3 Bucket (Website Assets) S3 Buckets (Logs) No files in place yet for our website, but it works
  17. Construct handles uploading files from a directory, `public`, to our S3 bucket Creates a Lambda function and uses CloudFormation Custom Resources to put files into the S3 Bucket CloudFrontToS3 construct provides properties to the resources it creates After deployment we have a working website at this point, there is still a lot you can do to improve but it works!
  18. AWS has great CDK Best Practices document Much of what I outline is from or evolves out of AWS’s published best practices Some of what I am about to say will go directly against what I just showed, but that’s ok Always exceptions Always iterate improvement QR Code destination: https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html
  19. Don't put all the code in the constructor! Joke: This isn't the matrix. We don't want to try and comprehend that wall of text Use Custom Constructs. Use Methods. Break it up! Don't have a 2000-line-long constructor Avoid a 2000-line-long CDK stack class, so prefer the constructs Sometimes you can't avoid a lot of repetitive code, but if you can. Do Photo Source: https://unsplash.com/photos/iar-afB0QQw (Free to use under the Unsplash License)
  20. Only split stacks if you need AWS recommends focusing on deployment requirements, but you can keep them together in a single code repository Stateful and stateless resources – DB vs Lambda – Enable termination protection on stateful stack to prevent deletes Stack per environment (ex, next slide) Mutli-region deployments (ex, 2nd slide) Image Source: https://pixabay.com/vectors/cube-building-blocks-tetris-3d-2026724/
  21. Common example, stack per deployment environment Environment-specific configuration passed in when you define the stack Deploy script selects the stack(s) based on the environment TIP: The CDK CLI tool supports wildcards when specifying stacks! Code Snippet: const app = new App()   new SampleStack(app, 'production', {   env: { region: 'us-east-1', account: '999999999999' },   hostname: 'myapp.example.com', })   new SampleStack(app, 'staging', {   env: { region: 'us-east-1', account: '000000000000' },   hostname: 'myapp-staging.internal.example.com', })
  22. Example of using L3 constructs and multiple stacks is my own website L3 Construct: “Redundant CDN” construct encapsulating all the setup for a distribution with an origin group Multiple stacks: 3 stacks to 3 different regions to setup the site Deploy secondary S3 bucket Deploy primary S3 bucket Deploy CDN and certifiance Also worth remembering you can use OOP when building everything Secondary stack is extended by the “primary stack” to add in replication, everything else is the same! Icons Source: https://aws.amazon.com/architecture/icons/
  23. Focus your CDK unit testing efforts on important constructs, critical infrastructure, and things you want to make sure a right If you're not careful, these unit tests can basically turn into a copy of your code, and that isn't want you need Like with any application, be careful that every change to code doesn't require a change to unit tests Skip less beneficial tests Don’t test that your custom Lambda construct defined a Lambda function. Test that it defined a Lambda with the special configuration your construct handles Snapshotting – Jest makes it easy, and it’s easy to overdo it If you use it too much, everyone will always run the tests so they update the snapshot Example of a good unit test: Situation: Custom CDK construct for Lambda to reuse a single IAM Role for most Lambdas in a stack, they all needed the same permissions Test: Define two Lambdas, ensure one IAM Role is created and both Lambdas are using that IAM Role Test: Define two Lambdas, one to use the IAM Role and one to use a different one, ensure the functions are using the correct IAM Role Overall, this is probably not an area to aim for 100% code coverage Image Source: https://pixabay.com/vectors/pyramids-blue-shape-egyptian-3d-23957/
  24. Thank you for attending QR Code: https://jbutz.dev/i38/resources