Virtually hosting images from S3

AWS Virtual Hosting

The CNAME DNS record should alias your domain name to the appropriate virtual hosted–style host name. For example, if your bucket name and domain name are images.johnsmith.net, the CNAME record should alias to images.johnsmith.net.s3.amazonaws.com.

The URL of my S3 hosted images looked like this:
“http://photos-crane.s3.amazonaws.com/wp-content/uploads/2014/09/DSC_0232.jpg”

  1. Go to the AWS Route53 dashboard, and click on Hosted Zones, and select your chosen hosted zone, and click “Go To Record Sets.”
  2. Click “Create Record Set”:
    a. NAME: photos-crane (your bucket name)
    a. TYPE: CNAME
    a. VALUE: photos-crane.stephenfranklin.info.s3.amazonaws.com
    a. Click “CREATE”

Here’s a photo. Click or hover over it to see it’s address:
DSC_0231s

Well that didn’t work… I’ll have to figure out later.

hosting a photo from Amazon S3

Hosting images on s3 for wordpress:
sudo apt-get install php5-curl
sudo service apache2 restart

Install these plug-ins in wordpress:
Amazon Web Services
Amazon S3 and CloudFront

1)Create a new IAM user and grant access to the specific services which this plugin will use (e.g. S3).
Go to AWS IAM > Create New Users > “wordpress”.
Download the credentials (User Name, Access Key Id, Secret Access Key).
2) Click on the user “wordpress” > Attach User Policy:
Add AmazonS3FullAccess
3) Copy the folowing code to your wp-config.php and replace the stars with the keys.

define( ‘AWS_ACCESS_KEY_ID’, ‘********************’ );
define( ‘AWS_SECRET_ACCESS_KEY’, ‘****************************************’ );

4) In wp-admin, go to AWS > S3 and Cloudfront. Hopefully it will already have access to your S3 buckets.
Choose the S3 bucket you want to use.

Here are my settings:
unchecked: Bucket is setup for virtual hosting (more info)
checked: Set a far future HTTP expiration header for uploaded files (recommended)
CloudFront Settings: not used.
checked: Copy files to S3 as they are uploaded to the Media Library
checked: Point file URLs to S3/CloudFront for files that have been copied to S3
checked: Remove uploaded file from local filesystem once it has been copied to S3
unchecked: Always serve files over https (SSL)*
checked: Copy any HiDPI (@2x) images to S3 (works with WP Retina 2x plugin)

And here’s an S3 hosted photo:
DSC_0232

  • The wp-admin Media menu seems not to work over https, so you get the broken image icon instead of the actual image, and they won’t upload to S3 or link to a post. But after unchecking the SSL option, uploading, and linking, the SSL option seems to have no effect on the posted images. The only difference in the html of the post is that the SSL option uses a href=https... instead of http.

Here’s another S3 photo:
DSC_0242