Today I set up my second Ember deployment to AWS. What follows is the consolidated recipe that comes from following the combination of my last two posts:
S3 Setup
Create Bucket
- Open the AWS S3 Console
- Click Create a Bucket
- Set the Bucket Name; I’ve set mine to match the
app
subdomain I am using:app.[appdomain].com
- Select a Region close to the app’s expected users (for me, this is US Standard)
- Click Create
Edit Bucket Permissions
- Select the
app.[appdomain].com
bucket, click Properties, click Permissions, and click Add bucket policy -
Copy and paste the following policy into the Bucket Policy Editor (change
app.[appdomain].com
to match the name of the bucket):{ "Version":"2012-10-17", "Statement": [{ "Sid": "Allow Public Access to All Objects", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::app.[appdomain].com/*" }] }
- Click Save
Enable Static Site Hosting and Routing Rules
- Within the bucket Properties, click Static Website Hosting
- Click Enable Website Hosting
- Set Index Document to
index.html
- Click Save
Make note of the app.[appdomain].com.s3-website-us-east-1.amazonaws.com
endpoint displayed uther the Static Website Hosting settings. It will be needed later for CloudFront.
Create SSL Certificate
- Open the AWS Certificate Manager Console
- Click Get started if no certificates exist or Request a certificate if there are existing certificates
- Under Domain name, enter the application subdomain
app.[appdomain].com
that will be used - Click Review and request
- Review the domain name, then click Confirm and request
- Check the email address associated with the domain registration for a certificate approval email; in the email, click the link to Amazon Certificate Approvals
- On the approval page, click I Approve
CloudFront Setup
Create Distribution
- Open the AWS CloudFront Console
- Under Web, click Get Started
- Fill Origin Domain Name with the S3 Hosting Endpoint (NOT the name of the bucket)
app.[appdomain].com.s3-website-us-east-1.amazonaws.com
- Set Viewer Protocol Policy to Redirect HTTP to HTTPS
- Set Forward Query Strings to Yes (if the app uses query params)
- In Alternate Domain Names (CNAMEs), enter the
app.[appdomain].com
custom domain that I want to use - Under SSL Certificate, choose Custom SSL Certificate (example.com)
- In the dropdown, select the ACM certificate for
app.[appdomain].com
- Set Default Root Object to
index.html
- Click Create Distribution
Add CloudFront custom error response
This will handle requests for other routes within the Ember application without using a hash-based redirect.
- Open the AWS CloudFront Console
- Click on the [Distribution ID]
- Click the Error Pages tab
- Click Create Custom Error Response
- Set HTTP Error Code to 404: Not Found
- Under Customize Error Response, click Yes
- Set Response Page Path to
/index.html
- Set HTTP Response Code to 200: OK
- Click Create
Domain DNS
- Open the domain’s DNS settings (mine are managed on DNSimple)
- Create a
CNAME
record that setsapp.[appdomain].com
as an alias for the CloudFront distribution at[cloudfrontcode].cloudfront.net
AWS Access Key Setup
- Open the AWS IAM Console
- Click Users, then click Create New Users
- In box 1, type a name for the user (I used the name of my Ember app), then click Create
-
Click Show User Credentials and copy the Access Key ID and Secret Access Key into a file named
.env.deploy.production
in the root of the ember-cli app:AWS_KEY=[Access Key ID] AWS_SECRET=[Secret Access Key] PRODUCTION_BUCKET=[AWS Bucket] PRODUCTION_REGION=[AWS Region] PRODUCTION_DISTRIBUTION=[CloudFront Distribution ID]
- Click close (and again to confirm) to return to the list of users
- Click on the new user, click the Permissions tab, and click Attach Policy
- Select the policies named AmazonS3FullAccess and CloudFrontFullAccess
- Click Attach Policy
ember-cli-deploy Setup
-
Install ember-cli-deploy and the plugin pack
$ ember install ember-cli-deploy $ ember install ember-cli-deploy-aws-pack
-
Deploy Ember application
$ ember deploy production