Home

Awesome

aws-static-site-with-cd

πŸš€ Automatically deploy static websites to AWS using a deploy agent

Contributions are welcome Quality checks Security checks Bump version and release Auto-versioned by bump-everywhere

Why

This setup has different goals that makes difference from other static website setups:

Get started

Step-by-step guide

❗ Prerequisite: A registered domain name for website, can be Route53 or somewhere else.

Manual deployment

❗ Not recommended. You can skip directly to automated deployment

  1. Deploy infrastructure
    1. Deploy dns-stack.yaml.
    2. Configure custom domain registrar
    3. Deploy certificate-stack.yaml
    4. Deploy web-stack.yaml
  2. Deploy application
    • Copy your site to S3 and invalidate CloudFront cache
    • πŸ’‘ You can call scripts to do that.

↑

Setting up automatic deployments

Estimated time: β˜• 10 min

  1. Deploy IAM stack
  2. Run your first build pipeline
  3. Configure your domain registrar

Deploy IAM stack

Deploy IAM stack using console
  1. Go to Cloud Formation home
  2. Click on "Create stack"
  3. Select "Upload a template file"
  4. Upload iam-stack.yaml
  5. Choose a name for your stack, see choosing a name
Choosing a name

↑

Run your first build pipeline

  1. Configure your deploy agent
  2. Run the deployment
Configure your deploy agent
  1. Add the secrets
  2. Create your build pipeline
  3. Run the deployment
Add the secrets
Create your build pipeline
Run the deployment

↑

Configure your domain registrar

↑

Architecture

Building blocks

AWS solution

↑

Automation

CI/CD to AWS

↑

Cost optimizations

↑

Security

Infrastructure security

↑

Deployment security

↑

DevSecOps

Any pull request or push to this repository is automatically linted for potential errors and also scanned for vulnerabilities.

Vulnerability scans runs also periodically each month to check against latest known vulnerabilities.

↑

CloudFormation

↑

iam-stack

IAM stack deployment automation

↑

certificate-stack

↑

dns-stack

↑

web-stack

↑

Default directory indexes

↑

CORS

When you import modules such as :

<script src="/exporter.js" type="module" ></script>
<script type="module">
import * as imported from "./exporter.js";
</script>

It'll make a CORS request to function. So S3 only allows the website itself to do CORS requests to ensure maximum security.

↑

Deployment scripts

↑

Signing sessions

↑

Extending

You can always copy the stacks and modify, however then you miss the updates. There's one more way to extend to templates and always keeping up-to-date easily:

  1. Name your stack as such: yourexistingwebstackname-extend
    • You must start with existing stack name as it'll then be granted permissions by IAM-stack.
    • You must then add -extend suffix as it's the only suffix allowed in IAM-stack.
  2. Write your logic, feel free to use exported variables from other stacks
  3. Deploy using the same role that deploys the extended stack
    • E.g. if you are extending web-stack you then use AWS_WEB_STACK_DEPLOYMENT_ROLE_ARN secret to claim the role.

❗ It's only WEB stack that's allowed to extend right now. Please create an issue if you'd like to extend other stacks as well.

Extending records to use e-mail

    name: "Infrastructure: Deploy web stack (extend)"
    run: >-
      bash "scripts/deploy/deploy-stack.sh" \
        --template-file ../site/.infrastructure/dns-records.yaml \
        --stack-name undergroundwires-web-stack-extend \
        --parameter-overrides "DnsStackName=undergroundwires-dns-stack RootDomainName=undergroundwires.dev" \
        --region us-east-1 \
        --role-arn ${{secrets.AWS_WEB_STACK_DEPLOYMENT_ROLE_ARN}} \
        --profile user --session ${{ env.SESSION_NAME }}
    working-directory: aws

↑

Examples

↑

Footnotes

  1. 64 chars for roles - 14 chars used by AWS - 21 chars longest role name (ResolveCertLambdaRole) + 1 hypens = 28 chars ↩