Survata S3 and Cloudfront deployments using Grunt

Survata S3 and Cloudfront deployments using Grunt

Introduction

Survata uses AWS Cloudfront, backed by AWS S3 buckets to serve our static assets.  Deployments are accomplished by running the "grunt" command and adding additional grunt options depending on which subdomains you wish to deploy.  You'll need to install the AWS Command Line Interface tools for these to work. Visit the link below for installation instructions. 

https://github.com/aws/aws-cli

Uploading SSL Cert

Unfortunately, adding an SSL cert for use by Cloudfront can only be done using the CLI. Here's an example below:

aws iam upload-server-certificate \
    --server-certificate-name survatacdn-2015-06-02 \
    --certificate-body file://survatacdn-wildcard-20150601.crt  \
    --private-key file://survata_com.private.pem \
    --certificate-chain file://survatacdn-bundle-20150601.crt \
    --path /cloudfront/survatacdn.com/

Reference: 

https://www.dbswebsite.com/blog/2014/06/24/installing-godaddy-ssl-certificates-on-aws-cloudfront/

https://bryce.fisher-fleig.org/blog/setting-up-ssl-on-aws-cloudfront-and-s3/

Grunt commands

Below are the various grunt commands for uploading the latest builds to S3. (in some cases, you may have to add --force to the end of the grunt command)

// deploy www and surveys to survata.com
grunt prod s3_surveys
grunt prod s3_www
 
// deploy www and surveys to survata-mirror.com
grunt mirror s3_surveys_mirror
grunt mirror s3_www_mirror

// deploy surveywall
grunt prod s3_surveywall
 
// deploy test surveywall (api-test.survata.net)
grunt mirror s3_surveywall_test
 
// deploy take link to survata.com
grunt prod s3_take
 
// deploy take link to survata-mirror.com
grunt mirror s3_take_mirror
 

Invalidations

After uploading the latest builds to S3, you'll have to invalidate the appropriate Cloudfront distribution(s) from Survata's AWS dashboard.  The easiest way to get to the dashboard is by accessing it via Meldium. Click on "CloudFront", then find the distribution that you need to invalidate and click on the linked distribution ID.  Then go to the Invalidations tab, click on the most recent invalidation, then click copy. A modal popup should appear with a button that says "Invalidate".  Whatever you do, DO NOT CLICK THIS BUTTON.  Just kidding - click the button.  The invalidation will begin and you'll see a spinner in the status column.  The invalidation should take 15-20 minutes but sometimes will take longer.  Once invalidation is complete, the latest code will be live.