Skip to content
/ aws-spa Public template

CDK script for deploying single-page-app to AWS S3

License

Notifications You must be signed in to change notification settings

lauravuo/aws-spa

Repository files navigation

SPA deployment to AWS

Instructions with CDK script for deploying single-page-app to S3. After executing manual steps from section prerequisities you can run the CDK script. The script will create

  • S3 bucket for storing the files
  • TLS certificate to region "us-east-1" via ACM
  • Cloudfront distribution with the TLS certificate for the S3 bucket
  • Route53 record in a pre-existing hosted zone for the cloudfront distribution
  • IAM user with S3 bucket update permissions for CI use

Prerequisities

  1. Make sure you have installed node.js, AWS CDK and Typescript:

    # node
    nvm install
    
    # aws cdk
    npm install -g aws-cdk
    
    # typescript
    npm install -g typescript
  2. You need AWS Account. Create IAM user and AWS Access keys via console if you don't have one already.

  3. Create a public hosted zone to AWS Route53 for your domain. If your domain registrar is different from AWS Route53, you need to store the AWS nameservers to your domain settings (via the domain registrar UI).

  4. Declare following environment variables:

    # default region for AWS e.g. eu-north-1
    export AWS_DEFAULT_REGION=<xxx>
    
    # IAM user access key ID
    export AWS_ACCESS_KEY_ID=<xxx>
    
    # IAM user secret access key
    export AWS_SECRET_ACCESS_KEY=<xxx>
    
    # default region for AWS e.g. eu-north-1
    export CDK_DEFAULT_REGION=<xxx>
    
    # AWS account number
    export CDK_DEFAULT_ACCOUNT=<xxx>

Steps

# install deps
npm install

# bootstrap CDK
cdk bootstrap

# deploy CDK
cdk deploy