Amazon S3 Bucket Creation - Best Practices for WordPress on AWS

Amazon S3 Bucket Creation

First, create an Amazon S3 bucket in the AWS Region of your choice. For steps, see Creating an Amazon S3 Bucket. Enable static website hosting for the bucket by following the guide for Configuring a Bucket for Website Hosting.

Create an IAM policy to provide the IAM user created previously access to the specified S3 bucket, and attach the policy to the IAM user. For steps to create the following policy, see Managing IAM Policies.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1389783689000", "Effect": "Allow", "Principal": "*", "Action": [ "s3:DeleteObject", "s3:GetObject", "s3:GetObjectAcl", "s3:ListBucket", "s3:PutObject", "s3:PutObjectAcl" ], "Resource": [ "arn:aws:s3:::wp-demo", "arn:aws:s3:::wp-demo/*" ] } ] }

Install and activate the W3TC plugin from the WordPress admin panel. Browse to the General Settings section of the plugin’s configuration, and ensure that both Browser Cache and CDN are enabled. From the drop-down list in the CDN configuration, select Origin Push: Amazon CloudFront (this option has Amazon S3 as its origin).

Browse to the Browser Cache section of the plugin’s configuration and enable the expires, cache control, and entity tag (ETag) headers. Also activate the Prevent caching of objects after settings change option so that a new query string is generated and appended to objects whenever any settings are changed.

Browse to the CDN section of the plugin’s configuration and enter the security credentials of the IAM user you created earlier, as well as the name of the S3 bucket. If you are serving your website via the CloudFront URL, enter the distribution domain name in the relevant box. Otherwise, enter one or more CNAMEs for your custom domain name(s).

Finally, export the media library and upload the wp-includes, theme files, and custom files to Amazon S3 using the W3TC plugin. These upload functions are available in the General section of the CDN configuration page.