{"id":13880965,"url":"https://github.com/scaffold-sh/aws-static-website","last_synced_at":"2025-07-16T17:31:31.789Z","repository":{"id":143790556,"uuid":"297156512","full_name":"scaffold-sh/aws-static-website","owner":"scaffold-sh","description":"This infrastructure uses AWS S3 to host a static website in a serverless way.","archived":false,"fork":false,"pushed_at":"2020-10-11T08:13:42.000Z","size":167,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-24T10:34:29.729Z","etag":null,"topics":["aws","cloudfront","codebuild","codepipeline","s3","scaffold"],"latest_commit_sha":null,"homepage":"https://scaffold.sh/docs/infrastructures/aws/static-website","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scaffold-sh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-09-20T20:18:53.000Z","updated_at":"2023-11-29T03:54:36.000Z","dependencies_parsed_at":"2024-01-16T12:02:18.188Z","dependency_job_id":null,"html_url":"https://github.com/scaffold-sh/aws-static-website","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scaffold-sh/aws-static-website","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffold-sh%2Faws-static-website","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffold-sh%2Faws-static-website/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffold-sh%2Faws-static-website/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffold-sh%2Faws-static-website/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scaffold-sh","download_url":"https://codeload.github.com/scaffold-sh/aws-static-website/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffold-sh%2Faws-static-website/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265527549,"owners_count":23782480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cloudfront","codebuild","codepipeline","s3","scaffold"],"created_at":"2024-08-06T08:03:42.389Z","updated_at":"2025-07-16T17:31:31.411Z","avatar_url":"https://github.com/scaffold-sh.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/assets/aws.jpg\" alt=\"AWS\" width=\"200\" height=\"200\" /\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eAWS Static Website\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003e\n  \u003ca href=\"https://scaffold.sh/docs/infrastructures/aws/static-website\"\u003eDocumentation\u003c/a\u003e |\n  \u003ca href=\"https://scaffold.sh\"\u003eWebsite\u003c/a\u003e |\n  \u003ca href=\"https://medium.com/scaffold\"\u003eBlog\u003c/a\u003e |\n  \u003ca href=\"https://twitter.com/scaffold_sh\"\u003eTwitter\u003c/a\u003e |\n  \u003ca href=\"https://www.linkedin.com/company/scaffold-sh\"\u003eLinkedIn\u003c/a\u003e\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003e+ $1.5\u003c/b\u003e / month \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  \u003cb\u003e~ 4min\u003c/b\u003e / create\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/scaffold-sh/cli/blob/master/package.json\"\u003e\u003cimg src=\"https://img.shields.io/node/v/@scaffold.sh/cli\" alt=\"Node version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://yarnpkg.com/en/docs/install\"\u003e\u003cimg src=\"https://img.shields.io/badge/yarn-%3E%3D1.21-blue\" alt=\"Yarn version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://aws.amazon.com/cli/?nc1=h_ls\"\u003e\u003cimg src=\"https://img.shields.io/badge/aws-%3E%3D2.0-0b1b2c\" alt=\"AWS version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.terraform.io/downloads.html\"\u003e\u003cimg src=\"https://img.shields.io/badge/terraform-13.0-5c44db\" alt=\"Terraform version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/hashicorp/terraform-cdk\"\u003e\u003cimg src=\"https://img.shields.io/badge/cdktf-%3E%3D0.14-green\" alt=\"CDKTF version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/scaffold-sh/aws-static-website\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n```console\n$ scaffold aws:static-website\n```\n\nThis infrastructure uses the static website hosting capabilities of **[AWS S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html)** to host your static website in a **serverless way**.\n\nYour **GitHub account** will be connected to **[CodePipeline](https://aws.amazon.com/codepipeline)** and **[CodeBuild](https://aws.amazon.com/codebuild)**, so you will be able to build, test and deploy your favorite SPA and SSG frameworks (React JS, Vue JS, Gatsby JS, Hugo...) using the usual `git push` command.\n\nGiven that the S3 website endpoints do not support HTTPS, this infrastructure uses **[CloudFront](https://aws.amazon.com/cloudfront)** coupled with **[ACM](https://aws.amazon.com/acm)** to add a fully-managed SSL certificate to your website.\n\nTo use an ACM certificate with Amazon CloudFront, the certificate [must be requested](https://docs.aws.amazon.com/acm/latest/userguide/acm-regions.html) in the US East (N. Virginia) region.\n\nThis infrastructure also uses **[SSM Parameters Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)** to store your build environment variables.\n\n![](/assets/schema.png)\n\n### Requirements\n\n*   You will need a **GitHub** account to create this infrastructure. **Support for GitLab and BitBucket is coming soon.**\n\n*   If you plan to use an apex domain for your website (i.e. a root domain that does not contain a subdomain), make sure that your domain host support the ANAME, ALIAS or naked CNAME DNS record type.\n\n## Components\n\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003cth\u003eName\u003c/th\u003e\n            \u003cth\u003eSource\u003c/th\u003e\n            \u003cth\u003ePrice\u003c/th\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003cb\u003e\u003ca href=\"https://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html\"\u003eS3\u003c/a\u003e\u003c/b\u003e \u003csup\u003e(one bucket)\u003c/sup\u003e\u003cbr/\u003eS3 will be used to store your website source code.\u003c/td\u003e\n            \u003ctd\u003e\u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/src/lib/constructs/staticWebsite/bucket.ts\"\u003esrc/lib/constructs/staticWebsite/bucket.ts\u003c/a\u003e\u003c/td\u003e\n          \u003ctd\u003e\u003cb\u003eUsage\u003c/b\u003e\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003cb\u003e\u003ca href=\"https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html\"\u003eCloudfront\u003c/a\u003e\u003c/b\u003e \u003csup\u003e(one distribution)\u003c/sup\u003e\u003cbr /\u003eCloudFront will be used to serve your website from your S3 bucket.\u003c/td\u003e\n            \u003ctd\u003e\u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/src/lib/constructs/staticWebsite/cdn.ts\"\u003esrc/lib/constructs/staticWebsite/cdn.ts\u003c/a\u003e\u003c/td\u003e\n          \u003ctd\u003e\u003cb\u003eUsage\u003c/b\u003e\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003cb\u003e\u003ca href=\"https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html\"\u003eCodePipeline\u003c/a\u003e\u003c/b\u003e \u003csup\u003e(one pipeline)\u003c/sup\u003e\u003cbr /\u003eCodePipeline will be used to manage the deployments of your website.\u003c/td\u003e\n            \u003ctd\u003e\u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/src/lib/constructs/continuousDeployment/pipeline.ts\"\u003esrc/lib/constructs/continuousDeployment/pipeline.ts\u003c/a\u003e\u003c/td\u003e\n          \u003ctd\u003e\u003cb\u003e$1\u003c/b\u003e\u0026nbsp;/\u0026nbsp;month\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003cb\u003e\u003ca href=\"https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html\"\u003eCodeBuild\u003c/a\u003e\u003c/b\u003e \u003csup\u003e(one build project)\u003c/sup\u003e\u003cbr /\u003eCodeBuild will be used to run the builds of your website.\u003c/td\u003e\n            \u003ctd\u003e\u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/src/lib/constructs/continuousDeployment/build.ts\"\u003esrc/lib/constructs/continuousDeployment/build.ts\u003c/a\u003e\u003c/td\u003e\n          \u003ctd\u003e\u003cb\u003e+$0.5\u003c/b\u003e\u0026nbsp;/\u0026nbsp;month\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003cb\u003e\u003ca href=\"https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html\"\u003eACM\u003c/a\u003e\u003c/b\u003e \u003csup\u003e(one certificate)\u003c/sup\u003e\u003cbr /\u003eACM will be used to manage the SSL certificate of your website.\u003c/td\u003e\n            \u003ctd\u003e\u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/src/lib/constructs/staticWebsite/ssl.ts\"\u003esrc/lib/constructs/staticWebsite/ssl.ts\u003c/a\u003e\u003c/td\u003e\n          \u003ctd\u003e\u003cb\u003eFree\u003c/b\u003e\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003cb\u003e\u003ca href=\"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html\"\u003eSSM\u003c/a\u003e\u003c/b\u003e \u003csup\u003e(one parameter store)\u003c/sup\u003e\u003cbr /\u003eSSM Parameter Store will be used to store the environment variables of your builds.\u003c/td\u003e\n            \u003ctd\u003e\u003ca href=\"https://github.com/scaffold-sh/aws-static-website/blob/master/src/lib/constructs/staticWebsite/environmentVariables.ts\"\u003esrc/lib/constructs/computing/environmentVariables.ts\u003c/a\u003e\u003c/td\u003e\n          \u003ctd\u003e\u003cb\u003eUsage\u003c/b\u003e\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Environment variables\n\nThese environment variables will be **automatically** configured each time you create \u003ca href=\"https://scaffold.sh/docs/environments\"\u003ean environment\u003c/a\u003e (or \u003ca href=\"https://scaffold.sh/docs/sandboxes\"\u003ea sandbox\u003c/a\u003e) for your infrastructure.\n\n\u003ctable class=\"table table-striped table-dark\"\u003e\n\n\u003cthead\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"col\"\u003eName\u003c/th\u003e\n\n\u003cth scope=\"col\"\u003eDescription\u003c/th\u003e\n\n\u003c/tr\u003e\n\n\u003c/thead\u003e\n\n\u003ctbody\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eBUILD_COMMAND\u003c/th\u003e\n\n\u003ctd\u003eThe command that needs to be run to build your website (e.g. npm i \u0026\u0026 npm run build) (optional).\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eBUILD_OUTPUT_DIR\u003c/th\u003e\n\n\u003ctd\u003eThe directory where the build command output your website (e.g. build/) (optional).\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eDOMAIN_NAMES\u003c/th\u003e\n\n\u003ctd\u003eThe domain name(s) that you want to use for your website.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eENABLE_HTTPS\u003c/th\u003e\n\n\u003ctd\u003eWe need to wait for the ACM certificate to be \"issued\" to enable HTTPS. See the \"\u003ca href=\"https://scaffold.sh/docs/infrastructures/aws/static-website/after-install\"\u003eafter install\u003c/a\u003e\" section to learn more.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eGITHUB_BRANCH\u003c/th\u003e\n\n\u003ctd\u003eThe branch from which you want to deploy.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eGITHUB_OAUTH_TOKEN\u003c/th\u003e\n\n\u003ctd\u003eThe GitHub OAuth token that will be used by CodePipeline to pull your source code from your repository.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eGITHUB_REPO\u003c/th\u003e\n\n\u003ctd\u003eThe GitHub repository that contains your source code.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eGITHUB_REPO_OWNER\u003c/th\u003e\n\n\u003ctd\u003eThe owner of your GitHub repository. Can be a regular user or an organization.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eGITHUB_WEBHOOK_TOKEN\u003c/th\u003e\n\n\u003ctd\u003eA random token that will be used by CodePipeline and GitHub to prevent impersonation.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003c/tbody\u003e\n\n\u003c/table\u003e\n\n### Inherited\n\n\u003ctable class=\"table table-striped table-dark\"\u003e\n\n\u003cthead\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"col\"\u003eName\u003c/th\u003e\n\n\u003cth scope=\"col\"\u003eDescription\u003c/th\u003e\n\n\u003c/tr\u003e\n\n\u003c/thead\u003e\n\n\u003ctbody\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eSCAFFOLD_AWS_PROFILE\u003c/th\u003e\n\n\u003ctd\u003eThe AWS named profile used to create your infrastructure.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eSCAFFOLD_AWS_REGION\u003c/th\u003e\n\n\u003ctd\u003eThe AWS region where you want to create your infrastructure.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eSCAFFOLD_AWS_S3_BACKEND_BUCKET\u003c/th\u003e\n\n\u003ctd\u003eThe AWS S3 bucket that will contain the Terraform state of your infrastructure.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eSCAFFOLD_AWS_S3_BACKEND_DYNAMODB_TABLE\u003c/th\u003e\n\n\u003ctd\u003eThe AWS DynamoDB table that will be used to store the Terraform state locks.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eSCAFFOLD_AWS_S3_BACKEND_KEY\u003c/th\u003e\n\n\u003ctd\u003eThe S3 bucket key under which your Terraform state will be saved.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\n\u003cth scope=\"row\"\u003eSCAFFOLD_RESOURCE_NAMES_PREFIX\u003c/th\u003e\n\n\u003ctd\u003eAn unique custom prefix used to avoid name colision with existing resources.\u003c/td\u003e\n\n\u003c/tr\u003e\n\n\u003c/tbody\u003e\n\n\u003c/table\u003e\n\n## After install\n\n**CloudFront will display a placeholder index file until the end of the first deployment.**\n\nThis infrastructure exports three Terraform outputs: `cloudfront_distribution_uri`, `pipeline_execution_details_url` and `ssl_validation_dns_records`.\n\nThe `cloudfront_distribution_uri` output value contains the URI of your CloudFront distribution. You could use it to access your website while your DNS are propagating.\n\nThe `pipeline_execution_details_url` output values contains the URL of your pipeline executions details.\n\nThe `ssl_validation_dns_records` output value contains the DNS records that you need to set in order to validate your ACM certificate (see below).\n\n### How do I set up my domain name?\n\nThe way you will set up your domain name will vary according to the presence or absence of a subdomain.\n\nIf your domain name doesn't have any subdomains, you will need to add two DNS records:\n\n- **Name:** \u003cempty\u003e or @\n- **Type:** ALIASE, ANAME or CNAME\n- **Value:** `cloudfront_distribution_uri`\n\n\u003cp\u003e\u003c/p\u003e\n\n- **Name:** www\n- **Type:** CNAME\n- **Value:** `cloudfront_distribution_uri`\n\nIf your domain name has a subdomain, you will need to add one CNAME record:\n\n- **Name:** subdomain\n- **Type:** CNAME\n- **Value:** `cloudfront_distribution_uri`\n\n### How do I set up HTTPS?\n\nThe `ssl_validation_dns_records` output value contains the DNS records that you need to set in order to validate your ACM certificate.\n\nOnce set, you will need to [wait for the status](https://console.aws.amazon.com/acm/home?region=us-east-1#/) of your certificate to switch from \"pending\" to \"issued\" to use it with your application load balancer.\n\nYou could then set the `ENABLE_HTTPS` environment variable to \"true\" in your local env file and run the `scaffold apply` command to update your infrastructure.\n\nIf you want to automate this process, you could use AWS Route 53 as your domain host then use the `aws_route53_record` and `aws_acm_certificate_validation` resources to wait for certificate validation. See the [Terraform documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation) to learn more.\n\n### How do I customize the build stage of my pipeline?\n\n[CodeBuild uses a YAML file](https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html) to describe all the steps that a stage requires. This file is located in the \u003ckbd\u003etemplates\u003c/kbd\u003e directory at the root of your infrastructure:\n\n```env\n# ./templates                                  \nbuildspec.yml\n```\n\nYou could update this file directly to customize your pipeline build stage.\n\n### How do I add environment variables to the build stage?\n\nTo add an environment variable to the build stage all you have to do is to add an environment variable that starts with `BUILD_` to your infrastructure code.\n\nFor example, let's say that you want to add a `TOKEN` variable to your build. You will first add it to your `.env` file:\n\n```env\n# .env\nBUILD_TOKEN=\n```\n\nThen, given that this value is secret you choose to define it in your local env file:\n\n```env\n# .env.{environment}.local\nBUILD_TOKEN=MY_SECRET_TOKEN\n```\n\nOne done, you could access your environment variables in all your buildspec file:\n\n```yaml\n# templates/buildspec.yml\n\nversion: 0.2\n\nphases:\n  pre_build:\n    commands:\n      - echo $TOKEN\n```\n\nRemember to run the `scaffold apply` command each time you update your infrastructure code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaffold-sh%2Faws-static-website","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscaffold-sh%2Faws-static-website","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaffold-sh%2Faws-static-website/lists"}