Using VPC Origins With AWS CloudFront
Recently AWS announced support for VPC Origins with CloudFront. Earlier we could use EC2 instances and Load balancers only if they had public IP associated with them. With this new feature, we can use internal load balancers/EC2 instances as CloudFront origin.
So let’s explore how to implement this feature.
Pre-requisite: Launch an EC2 instance and install httpd. Once installed, start the service and create a couple of web pages.
Step 1: In the security group associated with EC2 instance, allow acces to port 80 from CloudFront origin prefix list.
Step 2: Go to CloudFront->VPC origins and create a new origin. For Origin ARN, provide EC2 instance ARN.
Step 3: Now add a CloudFront origin. For origin domain, select your VPC origin id. For VPC origin domain, can specify private DNS address of your EC2 instance
Step 4: That’s all we need to do. Now try accessing CloudFront URLs and you should see the response from EC2 instance.