Using AWS CloudFront with resources in a VPC or behind a VPN
Codemia Knowledge Hub ·
To put CloudFront in front of resources that live inside a VPC (reached over a VPN), you expose them through a Network Load Balancer, AWS PrivateLink or a proxy, point the CloudFront origin at that endpoint, and use security groups and NACLs so only CloudFront can reach it. CloudFront also supports VPC origins, which let a distribution reach an Application Load Balancer, Network Load Balancer or EC2 instance in a private subnet directly, with no public endpoint.
What CloudFront provides
Amazon CloudFront is a content delivery network (CDN) that delivers data, videos, applications and APIs from edge locations close to users, which reduces latency. Content is served over HTTP or HTTPS. It offers DDoS protection through AWS Shield, encryption at rest, and integration with AWS Web Application Firewall (WAF).
CloudFront usually distributes public content, but sometimes the origin is private: for example, a private web server or an enterprise API hosted in a VPC and connected via a VPN for secure access.
Use cases
- Secure enterprise applications: serving enterprise applications that need secure, low-latency access over a VPN.
- Private APIs: API gateways integrated with CloudFront share resources securely between on-premises infrastructure and AWS.
- Secure content delivery: delivering content securely from a VPC to end users.
Architecture for a private origin
- Establish a VPN connection between your on-premises data center and AWS, so the VPC is reachable over a secure network.
- Deploy a Network Load Balancer (NLB) to distribute incoming traffic to instances inside the VPC, and configure it so CloudFront can reach it.
- Set up PrivateLink or a proxy in the VPC to connect CloudFront to your private resources and keep the connection private.
- Configure CloudFront. Create a distribution whose origin settings point to the NLB or the proxy, and enable SSL certificates if you need encrypted connections.
- Restrict access with security groups and NACLs so that only CloudFront can reach the resources in your VPC.
Operating the setup
- Performance: distribute resources correctly with load balancers.
- Security: use AWS Identity and Access Management (IAM) to control who can change CloudFront configurations.
- Monitoring: use CloudFront's built-in AWS CloudWatch metrics to monitor network performance and security.
Related reading
- AWS cloudfront not updating on update of files in S3
- AWS CloudFront redirecting to S3 bucket
- AWS CloudFront returns http 307 when origin is S3 bucket
- AWS Cloudwatch Filter and Pattern Syntax
- AWS CodeBuild failed CLIENT_ERROR authorization failed for primary source and source version
- AWS Cognito - Enabling MFA Error MFA cannot be turned off if an SMS role is configured
- AWS Cloudwatch Log - Is it possible to export existing log data from it?
- AWS Cloudwatch log stream name not recognised
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.