Donut Shop Part 3

The Problem

AWS (and other cloud providers like Azure, GCP, etc) are powerful toolboxes for building any sort of application. However, with great power comes great responsibility (and complexity). I want to build a backend for my Donut Shop app (ie, a data store and REST API), so will need several components to work together (DynamoDB, Lambda, API Gateway). And while I could create these manually in the AWS console, that would be bush league. A missed opportunity for learning, and building something scalable. Because once this is built, I’m naturally going to want a robust ecosystem with different environments (dev, stage, test, prod), and a fully automated CI pipeline!

Intro to CDK

OK, now that we’ve got the AWS SSO things working correctly, it’s time to crack open the AWS CDK tutorial. This tutorial will walk me through creating a simple app (seems to be just an S3 storage instance), but is a good start for utilizing the CDK. I’ve created a new Github repository (donut-shop) to track the work.

CDK Workshop

After finishing the introductory walkthrough, it’s time for something more involved. AWS has a CDK Workshop that involves a more complete example. After working through the Typescript Workshop, I’ve learned:

  • How to create my own construct (a “proxy” lambda function that intercepts API Gateway calls, and records the invocation count of each path in a DynamoDB table)
  • How to consume an external construct using NPM.
  • Odds and ends (how to troubleshoot issues with a deployed CDK stack, etc)

From here, there are some advanced steps in the CDK workshop, such as testing and pipelines. I’d like to dive into the pipeline portion (so I can deploy stacks in dev/test/prod), but this workshop tutorial seems to use CodeCommit, AWS’s source control repo. I’d rather use Github, so I may have to do some researching next…We’ll see what I find!

Notes and Decisions

Some notes and decisions made along the way:

  • Language - Typescript. Javascript is a great choice for a full-stack app, because it runs both in front and back. And Typescript’s use of static types introduces all sorts of benefits (compile-time checks, IDE support, etc). There’s a learning curve with TS, and it complicates the development pipeline a tiny bit, but it’s worth it (and worth learning). More info in the ChatGPT Q/A below.
  • cdk init creates a git repository within the folder I’ve created for this CDK app. And within that, a fully functional node app, complete with package.json, tests, etc. I think it’ll take a minute to mentally wrap my head around this - the app within the app, that’s responsible for deploying the app. Cool.
  • I finally realized I could default my profile in the cdk.json file with something like this:
    "profile": "admin-1",
    

    saves me the time of typing “–profile admin-1” with every cdk execution.

Chat GPT

Here are some highlights of ChatGPT helping accelerate my work.

what is a good gitignore template for a react project, with an AWS/TS backend? For a React project with an AWS/TypeScript backend, you can use the following .gitignore template to exclude common files and directories that are typically unnecessary to include in version control: (Omitted, look [here][gitignore]{:target="_blank"} for what it produced)
what are advantages of typescript over javascript ChatGPT TypeScript offers several advantages over JavaScript, which make it a preferred choice for many developers, especially in large-scale projects or teams. Some of the key advantages of TypeScript include: 1. Static Typing: TypeScript introduces static typing, allowing developers to define types for variables, function parameters, and return types. This helps catch type-related errors during development, leading to fewer runtime errors and improved code quality. 2. Enhanced IDE Support: With static typing, IDEs can provide better code completion, navigation, and refactoring tools. TypeScript's type system enables IDEs to offer more intelligent suggestions and detect errors in real-time, leading to improved developer productivity. 3. Code Maintainability: TypeScript's static typing makes code more self-documenting and easier to understand. By explicitly defining types, developers can better understand the structure of the codebase, leading to improved code maintainability and easier collaboration among team members. 4. Early Error Detection: TypeScript performs type checking at compile-time, catching many common errors before runtime. This results in faster feedback loops during development and reduces the likelihood of encountering runtime errors in production. 5. ECMAScript Compatibility: TypeScript is a superset of JavaScript and is designed to be fully compatible with existing JavaScript codebases. Developers can gradually introduce TypeScript into their projects and leverage TypeScript's features alongside existing JavaScript code without requiring a complete rewrite. 6. Tooling and Ecosystem: TypeScript has a rich ecosystem of tools and libraries that enhance development workflows. This includes popular frameworks like Angular, React, and Vue.js, which provide first-class TypeScript support. Additionally, TypeScript integrates well with popular build tools, testing frameworks, and package managers. 7. Future JavaScript Features: TypeScript often includes features from future versions of JavaScript (ECMAScript) before they are officially standardized and widely supported by browsers. This allows developers to use modern language features and benefit from language enhancements without waiting for browser support. 8. Stronger Codebase: By enforcing stricter rules and providing better tooling, TypeScript encourages writing cleaner, more maintainable code. This results in a stronger codebase that is easier to maintain, refactor, and extend over time. 9. Overall, TypeScript offers a range of benefits that can improve developer productivity, code quality, and maintainability, making it a compelling choice for many software projects.
Written on March 26, 2024