Cloud Distribution with AWS
Think of cloud distribution as a form of caching. You need it once your website passes a certain threshold of users and outgoing data volume. The exact figure depends entirely on your setup:
- You may serve large files, and sending them from your own server can use up your available bandwidth.
- You may have many users and want to ease the load on your server by pushing part of it elsewhere.
This article shows how to do this with AWS CloudFront.
In the AWS Console, open CloudFront and create a Web distribution. On the creation page, first enter your domain name as the distribution origin (the primary source of your content).
Scroll down and pay attention to two more fields:
- Price class: Using only the US and Europe edge locations is cheaper. Choose this if your customers are located only in those regions.
- Alternate domain name: This is the address used to access content served by CloudFront. In this example, the subdomain is
cdn(short for content delivery network).
Note: The form has many other configurable fields. The three above are the ones that matter for this setup. Every field has its use, so you may want to come back later to fine-tune parameters.
When you’re done, click Create distribution and wait about 10 to 15 minutes. When the status shows Deployed, the distribution is ready.
Next, make the alternate domain name reachable.
- If you use Route 53: create an alias record pointing to the distribution.
- If you manage DNS elsewhere: create a CNAME record that resolves the alternate name (e.g.
cdn.brainware.ro) to the distribution domain name shown in the distribution’s properties (e.g.xxx1234.cloudfront.net).
With the AWS side configured, update your website so the resources you want distributed use the CDN-based URL.
There is no way around this with URL rewriting or .htaccess tricks, because those only act on requests that already arrive at your server. The goal is to avoid those requests altogether. With a cloud distribution, the first request for a resource is served by your own server, and subsequent requests (up to the TTL) are served by the cloud endpoints.
For WordPress sites, plugins can handle this for you, for example W3 Total Cache.
- The full list of edge locations (data centers used by CloudFront) is on the AWS CloudFront Details page.
- Check the CloudFront service limits, such as the number of requests served per second, even though a typical website is unlikely to exceed them.
- See the detailed pricing on the AWS website. You are charged by usage only, not for simply setting up a distribution. Costs combine traffic volume and number of requests. Because the next bill can’t be fully predicted, setting up a Billing Alarm is advised.
Note: This text was written by an AWS Certified Solutions Architect (Associate). Always work with an expert when setting up production environments.