Sign in to the AWS Management Console and open the S3 console at https://console.aws.amazon.com/cloudfront/.
Specify a delivery method
RTMP is being deprecated at the end of the year so web will be the only optino going forward.
For S3 and Cloudfront there is slightly different configuration depending if the site is a SPA or a traditional layered website with a nested folder setup. In cloudfront this is primarily around the Origin Access Identity.
Restrict Bucket Access: We want to protect the S3 bucket, so we will restrict bucket access. Select Yes for this option.
Origin Access Identity: If you are following this guide, I am assuming you have no Access Identity setup for this already. Select Create a New Identity and keep the default name (Comment) or rename to make sense for your use. I have never had to rename this in my cases but to each their own.
Grant Read Permissions on Bucket: To apply the new Access Identify permissions to the S3 bucket, you will want to select Yes, Update Bucket Policy. I will show you how to verify this later in this guide.
For sites setup as static hosting on S3 we need to use a custom origin. For CloudFront to get your files from a custom origin, the files must be publicly accessible and we can’t use OAIs. It is possible to restrict access to the buckets using custom headers. This is more specialized so for the purpose of this walkthrough we won’t use them. (Supplemental section to be added in the future to walk through this process).
Viewer Protocol Policy: You should select Redirect HTTP to HTTPS.
Allowed HTTP Methods: The default setting (GET, HEAD) will work for most static sites.
Compress Objects Automatically: You should select Yes to compress objects automatically. This will make the files transmitted smaller thus saving you money.
Alternate Domain Names (CNAMEs): This is where you enter the URL for your project. You can have multiple URLs for CNAMES here but if you used an SSL cert or created one with Certificate Manager, then these URLs should be included on the SSL cert.
SSL Certificate: Select your SSL cert from the drop down.Remember, it is important that the SSL cert contains all the URLs used in the setting above.
Default Root Object: This is typically the index.html file but sometimes the project may use another.
For the Default Root Object. This is typically the index.html file but for sites with S3 configured for static hosting we leave this blank.
Note to avoid your users getting a NoKeyFound error page when they try and access something on the site that doesn’t exist we need to configure our 404 error page on cloudfront. This can either be a custom page or in the case of an SPA redirect back to index.html. We will run through the SPA use case here.
HTTP Error Code: You want to customize the 404: Not Found HTTP error code.
Error Caching Minimum TTL (seconds): This is the time-to-live (TTL) which is how long the request will remain cached. For dev, I use a 0 value and for production I personally use a 300 value (5 mins).
Customize Error Response: You will want to set this to Yes, so you can customize the response.
Response Page Path: You will want to redirect the 404 error back to you SPA so you will want to enter /index.html or if your SPA uses something else, enter that here.
HTTP Response Code: You want to return a 200: OK for the response since this is a SPA.