Skip to content

Instantly share code, notes, and snippets.

@chrishart0
chrishart0 / next-static-site.ts
Created August 31, 2025 15:43
AWS CDK Construct for NextJS Static Site S3 + CloudFront
// lib/next-static-site.ts
// Next.js Static Hosting on S3 + CloudFront (CDK v2, TypeScript)
// - Next.js static export docs (App Router `"output": "export"`): https://nextjs.org/docs/app/guides/static-exports
// (Pages Router export: https://nextjs.org/docs/pages/guides/static-exports)
// - trailingSlash config (optional, helps generate `/route/`): https://nextjs.org/docs/app/api-reference/config/next-config-js/trailingSlash
//
// CloudFront + S3 bits:
// - Private S3 origins via OAI/OAC: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html
// - S3 Block Public Access (keep the bucket private): https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html
// - CloudFront Function to append `/index.html` (official example): https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example_cloudfront_functions_url_rewrite_single_page_apps_section.html
#!/bin/bash
# Load all environment variables from .env file into the system
# Check if .env file exists
if [ ! -f .env ]; then
echo "Error: .env file not found"
exit 1
fi
# Read .env file line by line
@chrishart0
chrishart0 / test.txt
Created October 29, 2024 16:03
test text file
hello world
@chrishart0
chrishart0 / testURL.sh
Created December 17, 2020 21:39
Test status code of URL hit
#/bin/sh
#Tests if file can be reached with curl, then an ifelse to act upon this.
#Sends downloaded file to /dev/null so you don't need to deal with it
#Relies on curl being installed
####################################
## Specify parameters for testing ##
test_URL='https://d1.awsstatic.com/logos/aws-logo-lockups/poweredbyaws/Powered-By_logo-horiz_RGB.87c70af8a8a34b68606524ade6261db083947a14.png'
desired_status_code=200
####################################