How to Connect an EC2 Instance to AWS CloudFront for Global Acceleration
How to Connect an EC2 Instance to AWS CloudFront for Global Acceleration

When your website is hosted on an AWS EC2 instance, you might notice users from different regions experience varying loading speeds. To fix this, AWS CloudFront—the global Content Delivery Network (CDN) from AWS—is your best ally. It reduces latency, boosts performance, and offloads your EC2 server traffic.
In this guide, we’ll walk you through how to connect your EC2-hosted website to CloudFront, step-by-step. By the end, you’ll have a globally accelerated website running smoothly on AWS.

Table of Contents

1. Prepare an EC2 Instance with a Deployed Website

You’ll first need a running EC2 instance that already hosts a website, such as one using Nginx or Apache.

✅ Example: If you visit http://your-ec2-public-dns/, you should see your homepage loading correctly.


2. Create a CloudFront Distribution and Set EC2 as the Origin

Step 1: Open the CloudFront Console

  1. Go to the AWS Management Console, search for CloudFront, and open it.
  2. Click “Create Distribution.”

Step 2: Configure the Origin Domain

  • In the Origin Domain field, paste your EC2 public DNS, for example:
ec2-xx-xxx-xx-xxx.compute-1.amazonaws.com
  • Protocol: Choose “Only HTTP.”
  • Leave other settings as default.

Step 3: Choose a Cache Policy

  • Select “CachingOptimized.” This is CloudFront’s default high-performance caching policy.

Step 4: Disable WAF (Web Application Firewall)

  • If you haven’t configured AWS WAF, choose “Do not enable security protection.”

Then click “Create Distribution.” CloudFront will start deploying your setup.

Related Reading: Cloudfront official introduction


3. Verify That CloudFront Is Serving Your EC2 Website

Once the deployment is complete, CloudFront will generate a unique domain name like:

dxxxxxxx.cloudfront.net

To verify:

  1. Open the CloudFront domain in your browser.
  2. If your website loads, it’s working!
  3. If you see a 502 error, try the following fix:

Fixing 502 Errors:

  1. Go to CloudFront → Distributions → Origins.
  2. Edit the origin settings and set the Protocol to HTTP.
  3. Save and wait for redeployment.
  4. Refresh your CloudFront domain — your site should now load normally.

4. Confirm That Requests Are Coming from CloudFront

You can verify this using your browser’s Developer Tools (F12 → Network tab):

  • Look for headers like:
via: 1.1 dxxxx.cloudfront.net (CloudFront)
x-cache: Miss from cloudfront 或 Hit from cloudfront

These indicate CloudFront is successfully caching and delivering your EC2 website content.


5. Conclusion

By following this guide, you’ve successfully integrated your EC2-hosted website with CloudFront, enabling global acceleration and improved availability.
This is a key step toward building a scalable, reliable cloud architecture.

At Elite Cloud, we’re an official AWS reseller and advanced consulting partner, helping businesses:

  • Launch and optimize AWS environments
  • Manage billing in NTD with local invoicing
  • Access exclusive pricing and technical support

Whether you’re migrating to AWS or upgrading your cloud setup, Elite Cloud offers 1-on-1 expert guidance to make it simple.

📌 Want to explore more CloudFront optimization tips or need help improving your cloud architecture? 👉 Contact Elite Cloud today.

author avatar
Kevin Chou
Marketing Manager at Elite Cloud. Specialized in cloud cost optimization, FinOps, and multi-cloud strategy across AWS, Google Cloud, and Azure. Experienced in digital marketing, analytics, and content strategy for enterprise cloud solutions.
AWS Cloudfront AWS EC2 AWS Tutorial