Skip to content

Website Delivery with CloudFront

Category Cloud & AWS Data & Serverless
Status 🟡 Partially completed
Repo nextwork-website-delivery-with-cloudfront
Original NextWork guide nextwork.ai

Learning project

Practice work following a NextWork guide, separate from my production projects.

📚 NextWork learning project. This is a practice project I built while working through NextWork's Website Delivery with CloudFront guide. It is part of my Learning portfolio and is fully separate from my production projects.

Category: Learning › Cloud & AWS Data & Serverless
Status: 🟡 Partial

Overview

Part 1 of the three-tier series is the presentation tier. The website files live in an S3 bucket that stays private. CloudFront, AWS's CDN, caches them at edge locations around the world and is the only thing allowed to read the bucket, through Origin Access Control (OAC) and a bucket policy scoped to the distribution's ARN.

Summary

The S3 side ran on real AWS (private bucket, public-access block, the 4 site files, and the CloudFront Origin Access Control). AWS refused to create the CloudFront distribution itself: "Your account must be verified before you can add new CloudFront resources." New accounts have to open an AWS Support case first. Everything that was created has been torn down.

The checks behind this are in docs/verification.txt.

Skills & tools

AWS, Serverless, Terraform, Infrastructure as Code, moto (AWS mock), Amazon S3, Amazon CloudFront, CDNs & caching, Origin Access Control, Bucket policies, HTTPS, HTML/CSS/JS

What I built

  • site/: the static website (HTML, CSS, JS).
  • main.tf: S3 bucket with public access blocked, object uploads with content types, an OAC, a CloudFront distribution (HTTPS redirect, default root object), and a bucket policy limited to the distribution.
  • perf_compare.py: secret mission. It benchmarks a slow 'origin' against a caching 'edge' and shows X-Cache: Hit/Miss behavior.

How to run

pip install -r requirements-dev.txt   # moto (local AWS mock) + boto3
./local-test.sh                       # terraform apply against the mock, run checks.py, then destroy

# Real AWS (costs money; use your own IAM user/profile):
terraform init && terraform apply      # mock_endpoint defaults to "" = real AWS
terraform destroy                      # clean up when done

CDN benchmark: python3 perf_compare.py

Verification

I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.

PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh && python3 perf_compare.py

Real AWS deployment (2026-12-02)

I deployed this project to a real, dedicated AWS learning account (us-east-1, kept separate from everything else I run), checked it, captured the output, and tore it all down right after. Every resource carried the tag Project=nextwork-website-delivery-with-cloudfront so I could prove nothing was left behind.

How I ran it: ./real-aws-run.sh (in this repo) does terraform init/apply with my AWS profile, runs checks.py against the real account, runs real-extra.sh for the live tests, and then always runs terraform destroy, even if a step fails.

Evidence (excerpt; the full, sanitized transcript is in docs/aws-real-run.txt, with the account ID redacted):

random_id.suffix: Creation complete after 0s [id=FzBc_w]
aws_cloudfront_origin_access_control.oac: Creation complete after 1s [id=EODB07BZZX6MU]
aws_s3_bucket.site: Creation complete after 1s [id=nextwork-three-tier-17305cff]
aws_s3_object.site["script.js"]: Creation complete after 0s [id=script.js]
aws_s3_object.site["style.css"]: Creation complete after 0s [id=style.css]
aws_s3_object.site["config.js"]: Creation complete after 0s [id=config.js]
aws_s3_object.site["index.html"]: Creation complete after 0s [id=index.html]
aws_s3_bucket_public_access_block.site: Creation complete after 0s [id=nextwork-three-tier-17305cff]
Error: creating CloudFront Distribution: operation error CloudFront: CreateDistributionWithTags, https response error StatusCode: 403, RequestID: 6d133de1-79ba-494b-9e9b-57a28d1d054e, AccessDenied: Your account must be verified before you can add new CloudFront resources. To verify your account, please contact AWS Support (https://console.aws.amazon.com/support/home#/) and include this error message.

(The real-extra.sh live checks then had no distribution to test, so the full transcript shows them failing harmlessly against an empty domain.)

Teardown

Resources were up from 20:11 to 20:12 CST on 2026-12-02, then destroyed and verified gone:

=== TEARDOWN 2026-12-02 20:12 CST ===
$ terraform destroy -auto-approve -input=false -no-color -var project_tag=nextwork-website-delivery-with-cloudfront
Destroy complete! Resources: 8 destroyed.
$ terraform state list   (should be empty)
$ aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=nextwork-website-delivery-with-cloudfront
$ live EC2 instances / volumes / VPCs tagged Project=nextwork-website-delivery-with-cloudfront (should be empty)
=== teardown verified 20:12 CST ===

Cost

Estimated cost of the real run: $0.00 (an S3 bucket with 4 small files for about a minute). The account has a $50/month budget with email alerts at $5, $20 and $40, and the whole AWS series is logged in a private spend ledger.

What isn't done, and why

The CloudFront distribution: AWS blocks new accounts from creating CloudFront resources until the account is verified through an AWS Support case, which only the account owner can open. Once that's done, ./real-aws-run.sh . deploys the whole thing unchanged. real-extra.sh then waits for the distribution and checks HTTPS delivery, the HTTP→HTTPS redirect, edge caching (x-cache Miss → Hit), and that the bucket stays private when accessed directly (403). The Terraform and checks are unchanged and still pass on the local mock.


Original project: https://nextwork.ai/projects/c1513937-a6bf-53e9-9512-a7d466c0e79c · Part of my NextWork Learning portfolio (hub).

Verification output

From docs/verification.txt:

$ PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh && python3 perf_compare.py

Success! The configuration is valid.

Apply complete! Resources: 10 added, 0 changed, 0 destroyed.
bucket = "nextwork-three-tier-167e7607"
cdn_domain = "pyrpor86x7lu5.cloudfront.net"
distribution_arn = "arn:aws:cloudfront::123456789012:distribution/YQGOH8Q6UU7VH"
distribution_id = "YQGOH8Q6UU7VH"
PASS: CloudFront serves index.html by default
PASS: viewers are redirected to HTTPS
PASS: origin is the S3 bucket via OAC
PASS: bucket blocks all public access
PASS: bucket policy: only this distribution may GetObject
PASS: website files uploaded (['config.js', 'index.html', 'script.js', 'style.css'])
ALL 6 CHECKS PASSED
origin direct: 55.4 ms/request   via cache: 7.0 ms/request   speed-up: 8.0x
PASS: cached edge beats the origin on repeat requests

[exit code 0]