- Newest
- Most votes
- Most comments
Amazon CloudFront can cache static content (images, CSS, etc.) closer to your users, leading to faster load times, but you can improve performance and availability by accelerating dynamic parts of your web application. You can follow these steps to add CloudFront to your architecture, keeping it simple and focused on your current setup with a single EC2 machine:
1. Prepare the origin domain for CloudFront
In Route 53, create a new A record (e.g., origin.yourdomain.com) that points to your existing Elastic IP address. This record will be specifically used by CloudFront to reach your EC2 instance.
2. Create the CloudFront Distribution
On CloudFront, create a new distribution. Use the A record you just created (origin.yourdomain.com) as the origin domain name.
3. Handle SSL certificates
Ensure you have a valid SSL certificate for yourdomain.com in the us-east-1 region of AWS Certificate Manager. This is required for CloudFront to handle HTTPS traffic for your main domain. On CloudFront, in the Custom SSL certificate setting of your distribution, select the certificate you have created in us-east-1. Finally, set the Alternate domain name as yourdomain.com.
4. Point your main domain to CloudFront
Change your original A record for yourdomain.com (the one pointing directly to the Elastic IP) to an ALIAS record. Point this ALIAS record to the CloudFront distribution domain name (something like d123.....cloudfront.net).
Important consideration
Please consider using a Load Balancer as an origin for CloudFront, instead of a single EC2 instance. This will allow you to easily add more EC2 instances behind it for improved resilience, and can boost overall security of your architecture too. You can do that after these steps, but ideally you can do that instead, and just use the domain name of the load balancer as an origin. Then you will be able to restrict access to you Application Load Balancer, allowing users to access it only through CloudFront, ensuring that you and your users get all performance, availability and security benefits of the AWS content delivery service.
Relevant content
- AWS OFFICIALUpdated 12 days ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 16 days ago
- AWS OFFICIALUpdated a year ago