www.awsgood.com
Amazon CloudFront is a pull-only Content Distribution Network (CDN). All incoming requests for assets on a CloudFront enabled site will go through the CDN’s cached version. If an asset has expired or is missing, a fresh copy is pulled from the the origin site directly.
Be sure that you:
When creating an AWS account, you will have to enter credit card information. This is required, but you will not be charged unless you exceed the usage limits of their free tier.
Identity and Access Management (IAM) allows you to manage all user access to AWS resources and services. Before you can use S3, you need to create an IAM user.
You can only view or download a user’s secret access key immediately after the user has been created. This information cannot be accessed at a later point in time.
Make sure you save the credentials in a secure location before leaving this page. You will need the access keys when configuring the Amazon S3 and CloudFront plugin.
Now you need to give the new user permission to manage S3 (Amazon Simple Storage Service), because that is where assets are stored.
You now have a user with full S3 access and are ready to configure WordPress.
There are several plugins that will help you manage cached assets in WordPress with CloudFront; however, for the sole purpose of incorporating CloudFront, this article uses the Amazon S3 and CloudFront plugin.
There are a few different ways you can install a plugin on a Pantheon hosted WordPress site. The following methods require your site to be in SFTP Mode.
Execute the following Terminus command to install and activate the Amazon S3 and CloudFront plugin:
terminus wp <site>.<env> -- plugin install amazon-s3-and-cloudfront --activate
In order for the Amazon S3 and CloudFront plugin to function, you also need to install the Amazon Web Services plugin:
terminus wp <site>.<env> -- plugin install amazon-web-services --activate
Access your WordPress Dashboard by appending /wp-admin to your Development site URL and log in using your WordPress credentials.
From within your WordPress Dashboard:
You already have your AWS user credentials, as they were generated in the steps above. For security reasons, you should not provide user credentials within the Settings page of this plugin as it will not be stored securely in the site’s database.
wp-config.php file located at the web root of your WordPress site using SFTP (replace the stars with your user credentials):
define( 'AWS_ACCESS_KEY_ID', '********************' );
define( 'AWS_SECRET_ACCESS_KEY', '****************************************' );
There are several other options available within this plugin for you to experiment with. Take a tour of the settings to find the best configuration for your particular use case.
Follow these steps within your WordPress Dashboard to test CloudFront:
If the URL contains your newly created S3 bucket, then you have followed all steps correctly and have successfully configured Amazon S3 services. If you still see your Pantheon Development URL, start over and repeat the previous steps.
Now for the final step: turning on Amazon CloudFront. These combined services will automatically distribute your media globally so your pages will load fast around the world.
You’re now sent to the CloudFront Distributions page. You will notice that your distribution is enabled and the status is “In Progress”. The amount of time this initial setup takes depends on the size of your media library. Once complete, Amazon CloudFront will serve all of your media.