Amazon CloudFront is a web service that speeds up the distribution of static and dynamic web content, such as html, css, javascript, and image files.

This article will cover the steps to host an Angular web app in AWS CloudFront.

You need appropriate permissions on S3, CDN and AWS Certificate Manager.

Web Development

Steps to configure CDN

  • Create an S3 bucket named webhosting
    • Create index.html with the following content
      <div "style="text-align:center""> You have successfully completed your website hosting! </div>
    • Upload index.html to the S3 bucket

  • Configure the bucket for Web Hosting
    • Select the bucket
    • Select “Properties”
    • Select “Static web hosting”
      i. For Index document enter index.html (Angular prod build generates index.html as the starting point for the website)
      ii. For Error document enter error.html (create a file called error.html to show a custom error message when users access a wrong URL)

    Configure the bucket for Web Hosting

    Static website hosting

Set Bucket policy

There are two possible options
  • Make the bucket public
  • If a custom policy is set, then make the content of the bucket publicly accessible.

Refer to this document to set bucket policy


Set Bucket policy

Create Cloudfront Distribution

  • Select services from the top menu
  • Select CloudFront
  • Select Create Distribution
  • Select Get started under “Web”


Create Cloudfront Distribution

Set “Origin Domain name” as the Endpoint of Static website hosting (Step No 2)


Set Origin Domain name as the Endpoint of Static website hosting

Default Cache Behavior Settings

Compress Objects Automatically – Select “Yes” for a better performance

Compress Objects Automatically – Select “Yes” for a better performance


Lambda Function Associations

Distribution Settings

HOST ANGULAR WEB APP IN AWS CLOUDFRONT

CNAME – website name. (Optional, use this for user-friendly website name)
If alternate domain is used, an ACM (AWS Certificate Manager) certificate has to be created

Refer to this document to create ACM.


Set the Default Root Object to index.html

In the above image, set the “Default Root Object” to index.html

We have built many angular applications. Contact us for your angular development needs.

Enable IPv6 and Distribution State