Deploying Frontend App to Amazon S3 using AWS CLI

We are going to deploy a one page static website to S3. Here is the Twitter Bootstrap 4 starter template that will do the job for our first deployment.

<!DOCTYPE html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <h1>Hello, world!</h1>

    <!-- jQuery first, then Tether, then Bootstrap JS. -->
    <script src="" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

We can create an S3 bucket using the command:

aws s3 mb s3://

The following command configures a bucket named my-bucket as a static website:

aws s3 website s3://my-bucket/ --index-document index.html --error-document error.html

In our case:

aws s3 website s3:// --index-document index.html --error-document error.html

Should the bucket name be or

Create a user that only has access to the website.

aws iam create-user --user-name clickplan-frontend-deploy

JSON response:

goes here-TODO

Create AWS credentials for the front end app deploy user.

aws iam create-access-key --user-name clickplan-frontend-deploy

Create singlebucket.json file.

    "Statement": [{
        "Sid": "Stmt12345678",
        "Action": [
        "Effect": "Allow",
        "Resource": [

What should be the value for sid? TODO We can provide the user permissions to delete files on S3 if it is deleted locally. This user gets full access only to the bucket.

aws iam put-user-policy --user-name clickplan-frontend-deploy --policy-name clickplan-frontend-s3-access --policy-document file://singlebucket.json

Create a AWS profile for the front end app deploy user.

aws configure --profile clickplan-frontend-deploy

We need to create an alias so that the domain name points to the bucket name.

aws route 53 change-resource-record-sets --hosted-zone-id "/hostedzone/Z1T19W0V4R87XY" --change-batch file://changebatch.json

The changebatch.json:

  "Comment": "Add S3 Bucket",
  "Changes": [
    "Action": "CREATE",
    "ResourceRecordSet": {
      "Name": "",
      "Type": "A",
      "AliasTarget": {
        "HostedZoneId": "Z3BJ6K6RIION7M",
        "EvaluateTargetHealth": false,
        "DNSName": ""

We can push website content by syncing the local content with S3.

aws s3 sync . s3:// --acl public-read --delete --profile clickplan-frontend-deploy

Now we can access our front-end app by hitting the Next step is to use Amazon CDN (Cloudfront) and put WAF in front.


Related Articles

Watch this Article as Screencast

You can watch this as a screencast Deploying Frontend App to Amazon S3 using AWS CLI

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.