Content delivery network distributions in Amazon Lightsail
An Amazon Lightsail content delivery network (CDN) distribution caches your website or web application content at worldwide locations. When your user requests content that you're serving through a distribution, the request is routed to the nearest location in terms of latency. Lightsail distributions are backed by the Amazon CloudFront global network, which serves content from servers in 84 cities across 24 countries.
Last updated: July 23, 2020
A Lightsail distribution uses a globally distributed network of servers, also known as edge locations, to provide faster delivery of your content to your users. To use a distribution, you first create and host your website or web application on a Lightsail instance, or multiple instances attached to a Lightsail load balancer. You then create and configure a Lightsail distribution to pull, cache, and serve content from your instance or load balancer. Your instance or load balancer, also known as your distribution's origin, is the definitive source of your content.
When your user requests content by visiting your website, which is being served through a distribution, the request is routed to the nearest location in terms of latency. Your distribution then performs one of the following actions:
If the content is already being cached in the edge location, your distribution immediately serves it to your user.
If the content is not yet being cached in that edge location, your distribution retrieves it from the specified origin, caches it, and serves it to your user.
Your content is cached in edge locations for the duration of the cache lifespan (time to live) that you specify for your distribution, so that other requests at the same location are immediately fulfilled. Your cached content is cleared from the edge location when it reaches its cache lifespan. Your distribution retrieves, caches, and serves content the next time a content request is routed to the edge location.
In the following diagram:
1 represents the origin of your distribution, such as a Lightsail instance that is hosting your website.
2 represents your distribution, or the edge locations that pull, cache, and serve content from your origin.
3 represents your users who are served content from the edge locations.
This diagram is for illustration purpose only and doesn't show actual edge locations. For more information about edge locations, see Edge locations and IP address ranges later in this guide.
This method of serving content is faster and more efficient than the traditional method of serving content from just one, central instance. Your users access your content from locations that are nearby, as opposed to all of your users accessing the same central instance that may be far away.
Using a distribution to cache and serve your content also reduces the load on your origin, because most requests are served by your distribution and not your instance or load balancer.
A distribution allows you to take advantage of TLS termination, which reduces the load on your origin by offloading the cryptographic processing to your distribution. You can use your registered domain name together with a Lightsail SSL/TLS certificate to enable Hypertext Transfer Protocol Secure (HTTPS) for your distribution. Your users establish an encrypted HTTPS connection to your distribution, while your distribution pulls content from your origin using HTTP.
Configure your distribution
These are the general steps to follow to serve your website or web application using a Lightsail instance and a distribution.
Create a Lightsail instance to host your content. The instance serves as the origin of your distribution. The origin stores the original, definitive version of your content. For more information, see Create an Amazon Lightsail instance.
Attach a Lightsail static IP to your instance. Your instance's default public IP address changes if you stop and start your instance, which will break the connection between your distribution and your origin instance. A static IP does not change if you stop and start your instance. For more information, see Create a static IP and attach it to an instance in Amazon Lightsail.
Upload your content and files to your instance. Your files, also known as objects, typically include web pages, images, and media files, but can be anything that can be served over HTTP.
(Optional) Create a Lightsail load balancer if your website requires fault tolerance. Then attach multiple copies of your instance to your load balancer. You can configure your load balancer (with one or more instances attached to it) as the origin of your distribution, instead of configuring your instance as the origin. For more information, see Create a Lightsail load balancer and attach instances to it.
Create a Lightsail distribution, and configure your instance or load balancer as the origin. At the same time, you specify details such as the cache lifespan of your content, and which elements of your website or web application are cached. For more information, see Creating Amazon Lightsail distribution.
(Optional) If your distribution's origin is a WordPress instance, you must edit the WordPress configuration file in your instance to make your WordPress website work with your distribution. For more information, see Configuring your WordPress instance to work with your Amazon Lightsail distribution.
(Optional) Create a Lightsail DNS zone to manage your domain's DNS in the Lightsail console. This allows you to easily map your domain to your Lightsail resources. For more information, see Creating a DNS zone to manage your domain’s DNS records in Amazon Lightsail. Alternately, you can continue hosting your domain's DNS where it's currently being hosted.
Create a Lightsail SSL/TLS certificate for your domain to use it with your distribution. Lightsail distributions require HTTPS, so you must request an SSL/TLS certificate for your domain before you can use it with your distribution. For more information, see Creating SSL/TLS certificates for your distribution in Amazon Lightsail.
Enable custom domains for your distributions to use your registered domain names with your distributions. Enabling custom domains requires that you specify the Lightsail SSL/TLS certificate that you created for your domains. This adds your domains to your distribution and enables HTTPS. For more information, see Enabling custom domains for your Amazon Lightsail distributions.
Add an alias record to your domain's DNS to begin routing traffic for your domain to your distribution. After you add the alias record, users who visit your domain are routed through your distribution. For more information, see Pointing your domains to your Amazon Lightsail distributions.
Test that your distribution is caching your content. For more information, see Testing your Amazon Lightsail distribution.
Edge locations and IP address ranges
Lightsail distributions use the same edge servers and IP address ranges as Amazon CloudFront. For a list of the locations of CloudFront edge servers, see the Amazon CloudFront Product Details page. For a list of the CloudFront IP ranges, see the CloudFront global IP list.
Additional information about distributions
Here are some articles to help you manage distributions in Lightsail: