October 8, 2020 · Image Processing cdn Amazon Simple Storage Service aws s3

How to turn your S3 Bucket into a CDN via CloudFront

Having Amazon serve your image through their awesome CDN is dead simple and it can be a useful ingredient in your image processing solution. It's also about $0.12/GB per month... cheap.

Log into your Amazon account via the Amazon Console. Click on "CloudFront".

Once you have clicked on CloudFront, fint the "Create Distribution" link, which will either be at the top, or if you are a first time user, might be in the middle of the console page as well. Either way, click "Create Distribution".

You can use the default "Download" option on this page, and simple click the "Continue" button.

On the Settings page, click in the Origin Domain Name box, and you will get a dropdown of all your S3 buckets. Choose your bucket you want to be served from the CDN. Leave the other settings alone and click the "Create Distribution" button.

Viola! You now have a CDN that uses the images from the S3 bucket you chose on the settings page. The CDN will have some unfriendly url like uweoqruqyr.cloudfront.com (which will be the new base url for your images, like https://uweoqruqyr.cloudfront.com/mykey/foo.jpg)

You can go to your DNS provider and just add a CNAME that can map this to some friendly url like "cdn.myawesomeapp.com")