Share E-Book

AuthorSam Ward Biddle, Kyle T Jones

Looking to accelerate development and build cloud native applications with AWS Cloud Development Kit? Through hands-on projects, you'll learn the basics of AWS CDK, the tool of choice for many of the world's largest technology companies. Informed by real case studies and years of work with enterprise-scale cloud architectures, this book will benefit both novice and advanced cloud developers. It's complete with step-by-step explanations of essential concepts, practical examples, and self-assessment questions to help you build a shareable portfolio of completed projects, demonstrating your ability to build cloud infrastructure at scale. You'll explore: Basic cloud computing concepts, including the AWS Well-Architected Framework End-to-end cloud native software and infrastructure as code The benefits of a reusable code library to accelerate your projects Functional modules of code that can stand alone or build toward an integrated cloud application

AI Reading Assistant

Summary and highlights from this book's index; jump to passages in the text

Passage locations
Tags
No tags
ISBN: 1098158768
Publisher: O'Reilly Media
Publish Year: 2025
Language: 英文
Pages: 258
File Format: PDF
File Size: 5.8 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Sam Ward Biddle & Kyle T. Jones Hands-On AWS CDK Building Cloud Native Applications with Infrastructure as Code
ISBN: 978-1-098-15877-4 US $64.99 CAN $81.99 CLOUD COMPUTING Looking to accelerate development and build cloud native applications with AWS Cloud Development Kit? Through hands-on projects, you’ll learn the basics of AWS CDK, the tool of choice for many of the world’s largest technology companies. Informed by real case studies and years of work with enterprise-scale cloud architectures, this book will benefit both novice and advanced cloud developers. Complete with step-by-step explanations of essential concepts, practical examples, discussions, and extension activities, this book will help you build a shareable portfolio of completed projects, demonstrating your ability to build cloud infrastructure at scale. You’ll explore: • Basic cloud computing concepts, including the AWS Well-Architected Framework • End-to-end cloud native software and Infrastructure as Code • The benefits of a reusable code library to accelerate your projects • Functional modules of code that can stand alone or build toward an integrated cloud application Sam Ward Biddle is a principal solutions architect focused on building industry products at AWS. Kyle T. Jones is a solutions architecture leader for energy and utilities at AWS. Hands-On AWS CDK “AWS CDK has an empowering role. For many young people utilizing tech-driven solutions that cross borders, this book is a welcome toolkit.” Eunice Ajambo, economist, United Nations “Hands-On AWS CDK offers a brilliantly structured and project-driven approach, making it the ultimate guide for developers to master cloud native application development using AWS CDK while building real-world, portfolio-ready projects.” Gwanhoo Lee, PhD, chair of the Department of Information Technology and Analytics, American University “Finally, a hands-on, project-based CDK book that takes readers on a very enjoyable journey to learning the AWS CDK.” Andy Taylor, senior network solutions architect, AWS
Praise for Hands-On AWS CDK AWS CDK has an empowering role. With many young people globally as agents of change utilizing tech-driven solutions that cross borders, this book is a welcome toolkit. As cloud native technologies such as AWS CDK continue to evolve, they open up new opportunities for young developers around the world to participate in building scalable, automated infrastructure. By leveraging the power of programming languages, youth can contribute to the global movement of technology-driven international development, creating more accessible, efficient, and sustainable solutions for the future. —Eunice Ajambo, economist, United Nations This is an exceptional resource that not only demystifies cloud infrastructure but equips you to build real, impactful solutions with confidence. The practical, project-driven approach makes it a must-read for anyone serious about mastering cloud native development in AWS. —Jeffrey Rosenbaugh, senior director of professional services, Lucid Software Finally, a hands-on, project-based CDK book that takes readers on a very enjoyable journey to learning the AWS CDK. The writing style, content breadth, and depth applied to a fun and useful project make the book hard to put down, except to get your hands on the keyboard to get coding. —Andy Taylor, senior network solutions architect at AWS and self-confessed network automation nerd Hands-On AWS CDK offers a brilliantly structured and project-driven approach, making it the ultimate guide for developers to master cloud native application development using AWS CDK while building real-world, portfolio-ready projects. With its emphasis on hands-on learning, practical examples, and thoughtful explanations, this book not only
teaches the technical aspects of AWS CDK but also fosters a deeper understanding of modern cloud practices, including automation, security, and generative AI integration. —Gwanhoo Lee, PhD, chair of the department of Information Technology and Analytics, American University Hands-On AWS CDK works for everyone, whether you’re just starting out or you’re a seasoned pro. Beginners can follow the step-by-step projects to build their skills, while experienced developers can jump around to find exactly what they need. It’s a practical guide that grows with you as you learn. —Andrew Humphreys, director of product management, HyperTunnel
Sam Ward Biddle and Kyle T. Jones Hands-On AWS CDK Building Cloud Native Applications with Infrastructure as Code
978-1-098-15877-4 [LSI] Hands-On AWS CDK by Sam Ward Biddle and Kyle T. Jones Copyright © 2025 Sam Ward Biddle and Kyle T. Jones. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Megan Laddusaw Development Editor: Michele Cronin Production Editor: Aleeya Rahman Copyeditor: Krsta Technology Solutions Proofreader: Audrey Doyle Indexer: nSight, Inc. Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea April 2025: First Edition Revision History for the First Edition 2025-04-14: First Release See https://www.oreilly.com/catalog/errata.csp?isbn=0636920963257 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Hands-On AWS CDK, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors and do not represent the publisher’s views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Getting Started with CDK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What You Will Build 2 Project 1: The Shared Project 2 Project 2: The Portfolio Project 5 Prepare Your Learning Environment 6 Set Up Your Cloud Development Environment 7 Set Up Your AWS Account 7 Set Up Your AWS Budgets 8 Create an Admin IAM User 11 Sign In and Generate Keys for Your CDK Developer User 11 Set Up the AWS CLI 12 Set Up Your Local Development Environment 14 Set Up Visual Studio Code 15 Set Up Git and GitHub 15 Install Prerequisite Packages and Software 16 Infrastructure as Code and Automation 17 How Infrastructure as Code Works 18 How CDK Works on AWS 18 AWS CloudFormation, AWS CDK, and Terraform 19 Getting Unstuck 19 Chapter Synth 20 Discussion 20 Extension Activities 21 v
2. Hello, CDK!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Project Architecture: Build a “Hello, CDK” Lambda Function 24 Generate a New CDK Application 24 The Structure of a CDK Application 25 Understanding Application Stacks 28 Installing Dependencies 29 Building a CDK Application 30 Bootstrap Your CDK Application 31 Synthesize Your CDK Application 32 Project Tutorial: Deploy a “Hello, CDK” Lambda Function 33 Define Your Lambda Function Infrastructure 34 Define Your Lambda Function Application Logic 35 Deploy Your Function 36 Test Your Function 37 CDK Documentation 39 Basic CDK Commands 40 CDK to CloudFormation 41 Getting Unstuck 41 Chapter Synth 42 Discussion 42 Extension Activities 43 3. Introducing CDK and AWS Constructs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Project Architecture: Greeting S3 Bucket 45 Defining L1, L2, and L3 Constructs 46 Project Tutorial: Deploy an S3 Bucket 47 Project Preparation 47 Level 1 Construct 47 Level 2 Construct 48 Level 3 Construct 49 Why Use L1, L2, and L3 Constructs? 52 Documenting Your Code 53 Getting Unstuck 56 Chapter Synth 57 Discussion 58 Extension Activities 58 4. Integrating CDK Constructs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Project Architecture: Dynamic Lambda Greeting 60 Add an S3 Event Notification 60 vi | Table of Contents
Using Parameters and Overrides 68 Getting Unstuck 69 Chapter Synth 70 Discussion 70 Extension Activities 71 5. Building Multistack CDK Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Project Architecture: Data Pipeline Microservice 73 Create a Shared Resources Stack 74 Rename Your CDK Application 75 Redefine the Application Entry Point 75 Restructure Your Application for Multiple Stacks 75 Create a Shared Resources Stack 77 Build Your Data Pipeline Stack 80 Check Your Work 86 Getting Unstuck 87 Chapter Synth 89 Discussion 89 Extension Activities 90 6. Packaging and Deploying Lambda Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Project Architecture: Package and Deploy Lambda Functions with CDK 91 Create a Lambda Function to Transform CSV to JSON 93 Create a Lambda Function to Calculate Energy Use and Notify 98 Test, Deploy, Modify, and Destroy 103 Getting Unstuck 104 Chapter Synth 105 Discussion 105 Extension Activities 106 7. Extending CDK Constructs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Project Architecture: Custom S3 and Lambda Constructs 107 Create a Custom Lambda Function 109 Understand the CDK Features 112 Define Props 113 Define Your Construct 113 Document Your Construct 114 Use Your Construct 117 Create a Custom S3 Bucket Construct 117 Deploy Your Custom Constructs 120 Modify Your Application to Use the New Constructs 120 Table of Contents | vii
Test Your New Application 120 Getting Unstuck 120 Chapter Synth 122 Discussion 122 Extension Activities 123 8. Creating New Custom CDK Constructs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Project Architecture: Package and Deploy a Serverless API 125 Why REST API and Why Serverless? 127 Case Study 127 Go Build! 128 Create a Blank Construct 129 Test Your Custom Serverless API Construct 135 Getting Unstuck 136 Chapter Synth 138 Discussion 138 Extension Activities 138 9. Working with CDK Custom Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Project Architecture: Deploy Amazon Q Business Application 140 CDK Custom Resources 141 AWS Custom Resources 142 Choosing the Right Custom Resource Type 143 Go Build! 143 Test, Deploy, Modify, and Destroy 145 Test Your API 145 Getting Unstuck 146 Chapter Synth 147 Discussion 148 Extension Activities 148 10. Working with Third-Party CDK Constructs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Project Architecture: Extend Functionality of CDK Constructs 149 Go Build! 151 Do Your Research 152 Use the Amplify Web Application Construct 152 Test, Deploy, Modify, and Destroy 154 Getting Unstuck 154 Chapter Synth 156 Discussion 156 Extension Activities 156 viii | Table of Contents
11. Testing CDK Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Project Architecture: Extend Functionality of CDK Constructs 158 Precommit Hooks 159 Handle Secrets and Sensitive Data 160 Prettier, TSLint, and Other Formatting Tools 161 Infrastructure Tests with Jest 162 Write Your Own Jest Tests 163 Custom Commands 164 Getting Started with CDK-Nag 164 Integrating CDK-Nag with Your Manual Tests 165 Integrating CDK-Nag with Your CI/CD Pipelines and GitHub Actions 166 Remediating cdk-nag Errors and Warnings 167 Documenting Your CDK-Nag Remediations and DevOps Integrations 169 Getting Unstuck 171 Chapter Synth 172 Discussion 173 Extension Activities 173 12. Automating DevSecOps for CDK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Project Architecture: Automating Testing and Deployment 175 Precommit Hooks 176 Install Husky 176 GitHub Actions for CDK 177 Create Your Workflow 177 Provide Secure Permissions 178 Create Your GitHub Actions Workflow 178 Deploy to Test 182 Test 182 Deploy to Staging and Production 183 Document Your Deployment 183 CI/CD Concepts in CDK 184 Writing Deployment Scripts 185 Setting Up GitHub Actions 186 Integrating GitHub Actions for Deployment 187 Deploying with Git 188 Getting Unstuck 188 Chapter Synth 190 Discussion 190 Extension Activities 191 Table of Contents | ix
13. Contributing to CDK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Anatomy of an npm Library 193 Document and Publish Your Constructs 195 Contributing to CDK 196 What About Terraform? 197 Developer Collaboration with CDK 199 Architecting for Multicloud Environments with CDK 200 Blue/Green and Canary Deployments 202 Blue/Green Deployment 202 Canary Deployment 203 Comparing Blue/Green and Canary Deployments 204 Managing Configuration Settings for Different Environments 205 Getting Unstuck 205 Chapter Synth 207 Discussion 207 Extension Activities 207 14. Architecting, Building, and Publishing a Portfolio CDK Application. . . . . . . . . . . . . . . 209 Into the Working Backward Process 209 Step 1: Understanding the Core Problem 210 Step 2: Defining the Customer and Their Needs 210 Step 3: Defining Ideas and Solutions 211 Step 4: Validate and Establish Success Metrics 211 Step 5: Go Build! 212 Building Well-Architected Applications 212 Using the Well-Architected Framework with CDK 213 Operational Excellence for CDK 214 Security for CDK 216 Reliability for CDK 217 Performance Efficiency for CDK 219 Cost Optimization for CDK 220 Sustainability for CDK 221 Thank You! 223 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 x | Table of Contents
Preface The AWS Cloud Development Kit (CDK) is an open source software development framework that enables developers to define cloud infrastructure using familiar pro‐ gramming languages such as Python, TypeScript, Java, C#, and others instead of traditional JSON or YAML templates. The development of AWS CDK has evolved over time, driven by the need for a more efficient and familiar way to define and manage cloud resources. The idea for the CDK originated from customer feedback and the recognition that traditional Infrastructure as Code (IaC) tools using static configuration files had limitations in terms of expressiveness, reusability, and productivity. AWS CDK was introduced in 2018 as a new approach to IaC, allowing developers to define cloud infrastructure using their preferred programming languages, leveraging the full power of their language’s features and ecosystem. Since its initial release, AWS CDK has undergone continuous development and improvement. AWS has actively engaged with the community to gather feedback and make updates to the framework based on user needs. AWS CDK has seen regular updates with new features, bug fixes, and improvements to its performance, stability, and usability. The development of AWS CDK has also been influenced by the growing adoption of cloud native application development practices, such as DevOps and GitOps, which emphasize automation, repeatability, and versioning of infrastructure configurations as code. AWS CDK has integrated with popular development tools and practices, including integrated development environments (IDEs), source code repositories, continuous integration and continuous deployment (CI/CD) pipelines, and AWS CloudFormation, to provide a seamless and efficient experience for developers. AWS CDK has been extended to support multiple programming languages, allowing developers to choose the language that best fits their team’s skills and preferences. This has expanded the adoption of AWS CDK across a wide range of development xi
communities, making it a popular choice for defining cloud infrastructure in a more familiar and productive way. How This Book Is Structured This book follows a “project-first” approach. Feel free to skip to Chapter 1 if you want to get straight to building, and return to the Preface when you have questions. If you like guidance before you start building, read on. This book is an all-in-one project-based practical introduction to AWS CDK written for builders by builders. Through the course of this book, you will build two complete and well-architected cloud native applications. The first project is a digital Home Energy Coach complete with a data pipeline, serverless web application with authentication, and recommendation engine that we will build together bit by bit over the course of the book. Want to see what you will build? You can take a look at some artifacts from the sample project at https:// github.com/hands-on-aws-cdk-book/hands-on-aws-cdk-book-projects. This is also where you will find the code for the projects in this book. We recommend bookmarking this repository, and if you think it’s useful, you can even give it a star. We will start from scratch and progressively add additional elements to the project with each chapter. The second project is your own version of the first project. It will be unique to you and is intended to solve a problem specific to your interests, business, or engineering responsibilities. As you will see, the magic of CDK is in how common constructs can be used to build a variety of solutions. Throughout the book, we will encourage you to document, write tests, and push your projects to a GitHub repository that will become your CDK portfolio. Share your portfolio with current or prospective employers, friends, or the open source community. We invite you to join the Hands-on AWS CDK community and share links to your projects, screenshots, and video tours. We love demos. Why CDK? The AWS CDK is a unique IaC solution that offers several benefits compared to other IaC providers, such as traditional JSON or YAML templates, as well as other popular frameworks like Terraform or CloudFormation: Familiar programming languages CDK allows developers to define cloud infrastructure using familiar program‐ ming languages like Python, TypeScript, Java, C#, and others. This makes it easier for developers to leverage their existing programming skills and knowledge, resulting in increased productivity and a reduced learning curve. xii | Preface
Higher-level abstractions CDK provides higher-level abstractions, known as constructs, that encapsulate common cloud patterns and best practices. This enables developers to define infrastructure using reusable and composable components, making it easier to create and manage complex infrastructure configurations with less code. Improved productivity CDK’s programming language–based approach and higher-level abstractions make it more productive for developers to define, manage, and update IaC. CDK’s rich ecosystem of libraries and community-contributed constructs also provides a wide range of pre-built components that can be easily reused, further accelerating development and reducing duplication of efforts. Seamless integration CDK seamlessly integrates with popular development tools and practices, such as IDEs, source code repositories, CI/CD pipelines, and AWS CloudFormation. This allows for a smooth and efficient workflow, enabling developers to easily integrate infrastructure changes into their existing development processes and workflows. Full AWS service coverage CDK provides comprehensive coverage of AWS services, allowing developers to define and manage a wide range of cloud resources using the same programming language and constructs. This makes it a unified and consistent way to define infrastructure across different AWS services, reducing the need to switch between different tools or configurations. Flexibility and portability CDK allows developers to define infrastructure using programming languages, which provides flexibility and portability. CDK code can be easily reused across different AWS accounts, regions, or projects and can also be deployed to multiple cloud environments, making it a versatile choice for multicloud or hybrid cloud scenarios. Like you, we came to CDK a little unsure of what we were getting into. We were familiar with other tools such as Ansible, CloudFormation, Terraform, and even the occasional shell script for orchestration. But CDK quickly won us over because it made building cloud infrastructure much more similar to writing object-oriented application code. At AWS, there is less of a divide between “platform” and “applica‐ tion” teams, which we find tends to result in tighter integration between the software and the infrastructure. This has a lot of benefits including more reliable, secure, and cost-effective applications. Preface | xiii
We are passionate about teaching others the benefits of CDK and how to use it. On a personal level, we love CDK for some additional reasons: Building with CDK is fun Honestly—writing code still feels like magic, and orchestrating cloud services from a code editor feels like being a magician. We still can’t get over how fun it is to go from idea or business challenge to cloud native solution in an afternoon or a week or a month by writing CDK. Just wait till you get your first taste in Chapters 1 and 2. CDK is open source and you can contribute to it We love that CDK is open source and that you can contribute documentation, improvements, or even brand-new constructs. We have contributed several con‐ structs to the public CDK libraries and to additional private libraries, and we have built several open source solutions for customers using CDK. CDK allows you to benefit from the flexibility and reusability of an object-oriented programming language We covered this earlier, but it’s worth reiterating on a personal level. It. Is. So. Awesome. To define, instantiate, and extend classes rather than copying and past‐ ing declarative syntax. Writing CDK in object-oriented programming languages makes development quicker, and less prone to error, and is quite honestly more elegant, fun, concise, and effective. Just wait till you try it out. We think you won’t want to go back. CDK makes collaboration easier We have seen a lot of customers struggle with a siloed infrastructure devel‐ opment process, constantly reinventing the wheel, and experiencing difficulty maintaining consistent infrastructure operations. It’s very difficult to reuse declarative syntax in CloudFormation of Terraform templates, which often leads to a centralized and slow process of cloud adoption. CDK makes this a lot easier because teams can maintain central construct libraries that can be used as packages and maintained centrally while developers use them for their own projects. We have seen this accelerate development velocity while also improving security, financial operations, and cloud operations. CDK lets software developers also own/understand infrastructure Because CDK combines application logic with infrastructure, CDK helps reduce the need to silo infrastructure into ticketing systems that divide IT and Applica‐ tion teams. We have seen, and experienced, the power of CDK to let developers own and/or understand infrastructure, which often improves overall reliability, helps optimize cost, and contributes to greater agility in the development cycle. xiv | Preface
If you weren’t convinced that CDK is worth your time before reading this section, we hope you are now. We are confident that by the time you finish Chapters 1 and 2 and you’ve built your first two projects, you will be proudly flying the CDK flag. Are there CDK flags? Maybe there should be. Now that we have expressed our love and appreciation for CDK, we will further explain why we wrote this book and why we think you should keep on reading it. Why We Wrote This Book This is the book we wish had existed when we started learning CDK. We came together around the idea for this book because we wanted to build real projects in a context that was engaging and informative, and we wanted to feel well prepared to build real production cloud applications using CDK. Since such a book didn’t exist, we decided to write it for you. We know that time efficiency is important when you’re building a new technology. This book is meant to be a one-stop guide to learn the what, why, and how of CDK and build real projects that you can show or share as a digital portfolio. Who This Book Is For This book is for developers, students, hobbyists, and the cloud-curious. This book is for people who have tried AWS CloudFormation, Terraform, Ansible, and many other tools but wanted something more like object-oriented programming and less declarative. This book is for teams looking to adopt CDK. If you made it this far, this book is for you. How to Use This Book The book is a tool for you to use in the ways that best suit your needs. Here are some options for how you might use the book, but you get to decide how you use it: • Read this book sequentially from cover to cover. • Read this book as a reference text, consulting specific chapters as you need them. • Read this book as a free-for-all, picking random chapters and following along with projects as you go. We want this book to serve as a useful reference even after you have completed the projects. Our goal is for you to learn how CDK works, not to memorize specific recipes that produce standard outcomes. You can look those up as needed. If we were picking up the text for the first time, we would get comfortable with a computer to work on, a favorite beverage, and a quiet place. We would probably complete a chapter and corresponding project each in a single sitting, until we had built our own Preface | xv
portfolio project. After reading once, we would return to the text as a reference when building personal and work projects. We might recommend specific chapters to a curious friend and lend the book to them, always sure to get it back to lend to the next person. Why Projects First? You might find that this book is structured a little differently from your traditional technical guide or text. We put the projects at the very beginning of each chapter so that you can get “hands-on” first (as the title suggests). This means that some project sections may have you asking yourself, “Why am I doing this?”; “What does this even mean?”; and “Can you give me the theory and concepts, please?” We wrote the book this way for three reasons: • We talked with a lot of our target audience and they told us that they often just skip ahead to projects anyway. • In our teaching practice, we both have seen the “flipped classroom,” “expedition‐ ary learning,” and “constructivist” models work really well for learners who want to accelerate their skill development while developing long-term knowledge and understanding. • We wanted to keep your attention and make the book feel a bit like a guided adventure. Each chapter begins with a brief description of the project and learning goals. Then, we get straight into “now do this.” Don’t panic. We will explain what happened after the project. We included comments in the project code, and each project includes a completed and annotated “exemplar” that you can reference as you go. You may find that the things we ask you to do feel unfamiliar, challenging, or ambiguous. Trust us. If you complete the exercises and read the text for each chapter, then we think you will walk away with a deeper understanding of how to build something new with CDK, what it all means, why it works, and how to extend your knowledge within your own projects and contexts. Documentation If you have ever inherited undocumented code and struggled to make sense of it, you probably wished the person before you had taken some extra time to document each function, variable, and class with inline comments. If you have ever struggled through deploying a repository for the first time, you also probably wish the creator had thoroughly documented every step with copy/paste commands and visual dia‐ grams. No fun. xvi | Preface
There are competing theories on the role of documentation in code. Some people say that code should be self-documenting, meaning that the code itself is written so intuitively and clearly that very little additional documentation is needed. Within an organization, or even a shared project, this is sometimes possible. But we have found that the best way to write ergonomic, easy-to-understand, and easy-to-extend IaC is to document thoroughly within the code and within a README file. Documenting your code is a great way to deepen your own understanding of what your code is doing. When you write docstrings in TypeScript, you are forced to explain, in simple terms, what each class, function, and variable means; what services they deploy; and how to use them. Throughout this book, you will use JSDocs to document your code. This is the standard requirement for all open source contributions to the standard AWS CDK Library, and it has the added benefit of providing tab-completion typing within code editors. This means that the JSDoc strings that you write will pop up with little explanations of your code, making it easier for others to extend, use, and reuse the code that you write. Whatever your stance is on documenting code, try our approach to documentation. You might like it. And in either case, you will learn something from the exercise. Testing There are several schools of thought on testing code, especially IaC. Some engineers believe that every unit of code should have tests, and that every application should have several tests including end-to-end, functional, and integration tests. Some devel‐ opers practice test-driven development, in which they write a test before they write the deployable components of their code. We are test-driven development people. Each project will start small with a simple architecture. As we add more modules, the application will gradually become more complex. We use the AWS Well-Architected Framework as a guide for creating applications that do their job in the best way possible. The AWS Well-Architected Framework is a structured set of design principles to align applications to best practices. The framework has six pillars: Operational Excellence, Security, Reliability, Performance Efficiency, Cost Optimization, and Sustainability. What You Will Build Imagine you are the lead cloud architect, developer, and technical project manager for a cloud native software solution. You are tasked with building an open source software platform to help individuals track, analyze, and understand their home Preface | xvii
energy usage. This application needs to be relevant to homeowners, renters, and local utilities. The application will allow users to upload home energy use data in CSV format and as image files of a utility bill. Your boss asks you to deploy the platform using IaC on AWS (even though your boss is not 100% sure what that means). Your coworkers, Sam and Kyle, recommend that you use AWS CDK in TypeScript and that you write with application logic in JavaScript. By the end of the book, you will have two portfolio-ready projects that you can maintain on your public GitHub page to demonstrate your cloud development skills. The projects will prepare you with the skills and concepts necessary to build your own cloud native CDK application in the culminating capstone project chapter at the end of this book. In the next section, you will learn about the technical details and AWS services that will be used in the project. End of Chapter Organization Each chapter ends with several key elements, which we outline here. Getting Unstuck In each chapter, we provide a Getting Unstuck section that provides trouble-shooting tips and resources for common issues that may arise during the project. Chapter Synth Each chapter will end with a chapter synth section. It’s a CDK pun. You will get it soon. If you already think that is a funny joke, this book is going really well. If you have a better joke, please submit your issue to the project’s GitHub repository. Review The chapter synth begins with a review of the topics covered at the end of each chapter to help solidify your knowledge and skills. It is our way of reminding you of what you learned in the chapter and to set the stage for the review questions and extension activities. Discussion Each chapter includes optional discussion questions. It is an open book quiz (Hint: use this book), but if a question is challenging for you, we recommend reviewing the corresponding parts of the chapter. xviii | Preface