Pantheon's Global CDN makes it unnecessary to add a third party CDN, such as CloudFront, for most CDN use cases. While technically possible, stacking another CDN on top of the Global CDN adds potentially unnecessary complexity. Confirm whether your needs are met by the Global CDN before considering stacking another CDN on top of it.
CloudFront is a pull-only content distribution network. All requests for assets go through CloudFront, and if the CDN's cached version has expired or is missing, a fresh copy will be pulled from the origin (your site).
Before You Begin
Make sure that you have:
- A site with a CDN module or plug-in installed
- Signed up for Amazon Web Services and are familiar with the interface
Set Up A Drupal CloudFront Distribution
The first step in setting up CloudFront on your Drupal site is to create a new CloudFront distribution. This article will help you create a barebones configuration. If you require a more complicated configuration, refer to the AWS documentation.
A CloudFront distribution is not a Drupal distribution. A CF distribution simply refers to a controller that will be configured to deliver your assets to your website.
In the CloudFront console, click Create Distribution.
Select Download for the delivery method and click Continue. If you require streaming media (such as video or audio files), you'll need to choose the streaming distribution (not covered in this article).
Complete the fields to get the basic download distribution up and running.
- Origin Domain Name: example-domain.com. The Origin Domain Name will be either an Amazon bucket hostname (if you're using a bucket to store your assets) or a web server's hostname.
- Origin ID: Custom-dev-static.pantheonsupport.com. An identifier to easily identify the distribution.
- Alternate Domain Names (CNAMEs): www.example-domain.com. Add any alternative domains that point to your site.
- Distribution State: Enabled. Be sure to enable the distribution or your assets will not be delivered through the CDN.
Click Create Distribution. The CloudFront distributions table now shows your new distribution with a status of "In Progress". When your distribution is ready, the status will be "Deployed".
Configure the CDN Module In Drupal
Install and enable the CDN module. For more information, see Drupal.org to learn how to install and enable modules through the Drupal interface, or see Drush on Pantheon to learn how to work with modules using Drush.
Go to admin/config/development/cdn to get to the General Configuration tab.
Select Enabled and click Save Configuration.
Go to the Details tab. There are a couple of items to address:
Mode: Origin Pull. For the CloudFront configuration, use Origin Pull mode. File Conveyor mode allows integration with File Conveyor for more complicated configurations. Pantheon does not support File Conveyor.
Return to the CloudFront distributions table and copy the domain name for your new distribution.
CDN Mapping: https://my.cloudfrontcdndomain.net. Be sure to add the protocol in front of the domain name. For example, "https://my.cloudfrontcdndomain.net" will work but "my.cloudfrontcdndomain.net" may cause problems. Be sure to use HTTPS.
Return to the Drupal CDN module configuration and paste the domain name copied from CloudFront.
Click Save Configuration. Your assets should now be coming from your CloudFront distribution.
Verify Assets Are Coming From the CloudFront Distribution
Execute the following steps as an anonymous user (logged out).
Create an article on your site and upload an image to it.
View the article in your browser.
Right-click the image and copy its location.
View the image in a new tab. If the URL reflects the domain provided by CloudFront, your assets are coming from the CloudFront distribution. If it reflects the domain name of your site and doesn't mention the CDN domain, go back to the beginning and complete the steps again.
CloudFront Unable to Connect to Pantheon
If you find that CloudFront is unable to receive content from the origin (Pantheon) for HTTPS traffic, it's likely due to the Host HTTP header forwarded in the request. To resolve, switch Forward Headers behaviors setting from "All" to "None".