How to use S3 for static content hosting with CloudFront?

To use S3 for static content hosting with CloudFront, follow these steps:

  1. Create an S3 bucket: First, create an S3 bucket in the AWS Management Console and upload your static content files to it. Make sure to make the bucket publicly accessible by setting the correct permissions.

  2. Enable static website hosting: In the properties tab of your S3 bucket, enable static website hosting and set the index document and error document if necessary.

  3. Create a CloudFront distribution: In the CloudFront console, create a new web distribution and configure it to use your S3 bucket as the origin. Make sure to select the S3 bucket as the origin and set the default root object to the index document of your static website.

  4. Configure CloudFront settings: Set up additional settings for your CloudFront distribution, such as cache behavior, TTL (time to live), and HTTPS settings.

  5. Update DNS records: After your CloudFront distribution is deployed, update your DNS settings to point your domain to the CloudFront domain name.

  6. Test your website: Check if your static website is accessible through the CloudFront distribution URL. You can also test the performance by using tools like WebPageTest or GTmetrix.

By following these steps, you can effectively use S3 for hosting static content and leverage CloudFront for faster content delivery with low latency and high performance.