I have a simple static website idea, but I want to use an EC2 instance as the web server for some dynamic logic, while keeping the heavy media assets on S3. Is this standard? Should I just use CloudFront instead, or is there value in keeping the web server in the loop for the media requests? Looking for a simple, scalable architecture.
Architecting a web application to serve static assets via a CDN like CloudFront instead of proxying through an EC2 instance optimizes performance by reducing compute load, minimizing latency, and lowering overall egress costs.
7 answers
The choice between proxying through EC2 or utilizing a content delivery network rests on your latency and scalability requirements. Direct streaming through EC2 works if you need to perform real-time watermarking or on-the-fly transformations that are specific to a logged-in user, but it scales poorly and forces you to manage the throughput limits of your instances. Using CloudFront is significantly better when you need to serve high-volume static assets to a geographically dispersed audience because it caches data closer to the user and offloads the bandwidth burden from your compute tier entirely.
You should absolutely avoid keeping the web server in the loop for media requests unless you have a hard requirement for dynamic server-side access control. Routing media through EC2 increases latency, adds unnecessary ingress/egress costs, and creates a single point of failure that your architecture doesn't need. Offload the heavy lifting to S3 and place CloudFront in front of it to handle global distribution securely.
I remember auditing a mid-sized ecommerce platform back in 2018 where the developers insisted on proxying every static image through their EC2 instances to track user access patterns. The sheer overhead of those instances under load resulted in significant downtime during a holiday sale when the CPU cycles meant for the checkout logic were consumed entirely by image serving. It was a classic case of unnecessary architectural coupling that compromised the stability of their primary business process.
We eventually refactored the entire flow to pull assets directly from S3 via an OAC, which not only improved load times by nearly forty percent but also reduced their monthly compute bill significantly.
Using your EC2 instance as a middleman for static media is an inefficient pattern that ignores how modern edge distribution should be architected.
- Create a private S3 bucket to house your assets
- Configure CloudFront with an Origin Access Control to fetch from the bucket
- Allow your EC2 instance to only handle business logic requests
- Use signed URLs if you need specific authorization for your media files
Serving media directly through EC2 is a bad idea because it creates a bottleneck you do not want. Just use CloudFront. It is more scalable, cheaper, and standard practice for a reason.
To build a robust and scalable architecture, you should decouple your static assets from your compute layer entirely. Keeping the web server in the loop creates unnecessary vertical scaling requirements for your EC2 instances, which forces you to pay for expensive compute just to handle data throughput that could be managed by AWS storage and delivery primitives.
By using CloudFront as your entry point, you gain the benefit of global edge locations, which drastically reduces the time to first byte for your users while simultaneously shielding your web server from the load of serving large files. This transition effectively moves the static content workload out of the VPC boundary where it does not belong. If your dynamic logic needs to reference these files, ensure your application generates the correct object keys or signed URLs rather than acting as a relay. This approach adheres to the principle of least privilege and reduces the surface area for potential outages, ensuring your compute instances remain dedicated to the task of dynamic logic processing rather than acting as expensive, inefficient file transfer proxies.
That makes sense, Taylor. I’ve been struggling with my EC2 CPU usage lately, so moving static assets to CloudFront sounds like the relief I need to fix these performance issues.
Taylor, you're a lifesaver. My instances are crashing constantly under this load and I’m just trying to keep the site alive. I’ll shift everything to S3 immediately to stop the bleeding.
Stop trying to make your web server do two jobs. Just put CloudFront in front of the bucket and call it a day.
- Host your dynamic logic on EC2 or better yet a container
- Use an S3 bucket for the files
- Configure CloudFront to fetch those files
- Forget about routing media through your server
I’m sorry, Zoe, but I’m still a bit anxious about the bucket permissions. I’ve been reading the docs all morning, but your simple list helps me feel more confident about this.
Sorry to bother you, Zoe, but is it really that straightforward to configure? I’m always so worried about breaking the production environment when making these kind of architectural changes.
Zoe, thanks for the clear steps. I’m always second-guessing my setup, but this approach seems much cleaner than what I’ve been doing. I’ll start testing this in my staging environment today.


Cory, I really appreciate the advice. I spent hours yesterday Googling how to lower my egress costs, and your explanation finally makes the whole S3 and CloudFront integration click for me.