Heading image

Prerequisites

  1. Basic familiarity with AWS CDK for TypeScript.
  2. Read the first two posts in the “Working with the TypeScript AWS CDK” series.
  1. If you want to create the Route53 record, you will need to get the ACM ARN for your certificate and have a hosted zone ID ready.

Getting started

Plan for the CDK stack

  1. We want to create an S3 bucket to host the assets.
  2. We want to ensure we get a reference to the ACM certificate from the ARN.
  3. We want to instantiate a new CloudFront distruction with a custom domain and that certificate.
  4. We need to grab the hosted zone from the attributes of the custom domain tha we created.
  5. We need to assign an ARecord and AaaaRecord for the zone targeting the CloudFront distribution.

Adding the CDN stack code

Create an S3 bucket

Get reference to the ACM certificate

Instantiate a new CloudFront distribution

Get the hosted zone

Assign ARecord and AaaaRecord to CloudFront distribution

Adding the stack to the CDK app

Synthesizing and deploying the stack

Manually testing the stack

Example CDN success with networking information

Writing a test for our stack

Teardown

Summary

Resources and further reading

  1. AWS CDK for TypeScript
  2. workingoutloud.dev
  3. “Working with the TypeScript AWS CDK” series
  4. AWS CDK With TypeScript Foundations
  5. Using The AWS CDK With LocalStack And aws-cdk-local
  6. Final repository code

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store