Use Amazon CloudFront CDN to instantly improve the performance of your magento store

Stefan Wieczorek —  July 29, 2012 — 3 Comments

Use Amazon CloudFront CDN to instantly improve the performance of your magento store

In this post i will explain what Amazon CloudFront CDN is and how to use it with magento.

Whether you just launched a new magento store or are maintaining an existing one, sooner or later you will take a look at possible ways to improve the performance of your magento store.

What is Amazon CloudFront?

Amazon CloudFront is a web service which can be used to deliver static files like images, css, javascript or streaming content using a global network of edge locations.
If you have customers from Asia which requests your site in the US they get routed to the nearest edge location, so the content is delivered with the best possible performance.

Why should i use a CDN with Magento?

Easy Integration: The integration takes about 15 – 45 minutes, depending on your knowledge

Performance Booster: It’s really fast to use a edge locations around the world to deliver your static content.
Amazon CloudFront caches copies of your static content close to viewers, lowering latency when the download your static files.
It’s good way to offload your static files, all requests are handled by the amazon servers which decreases your server load.

Cost-Effective: Pay only for what you use. You only pay for the content that you deliver through the network.
Visit http://aws.amazon.com/cloudfront/pricing/ to get more information about pricing.

Reliable: Amazon CloudFront is built using a highly reliable infrastructure.

Step1: Configure Amazon CloudFront

1. Access CloudFront from the Amazon Web Services Management Console here: http://console.aws.amazon.com/cloudfront/home

2. Create a pull zone contribution by clicking “Create Contribution”.
Afterwards you should see a wizard in a dialog.

Ensure that the delivery method is set to “Download”.

Create CloudFront Contribution

3. Enter your Origin Domain Name and Origin Id

Amazon CloudFront Origin Domain Name

4. Configure the default behavior how CloudFront communicates with your origin

Amazon CloudFront Default Bahavior

5. Enter distribution Details

Alternate Domain Names (CNAMEs): This field is not required. If you want use your own domain name (for example assets.mgt-commerce.com) instead of the Cloudfront domain name (e.g. d1256.cloudfront.net) for the URLs for your files.

Amazon CloudFront - Enter Distribution Detail

6. When you are satisfied with the configuration, select “Create Distribution”. CloudFront will now generates then a domain for you to use. In our example it generates:

dxkds3d2lqja0.cloudfront.net

You can use this domain to deliver static content or your configured CNAMEs (e.g assets.mgt-commerce.com).

Before proceeding, you must wait for your CDN to propagate worldwide to the CloudFront servers.
This usually takes about 10 minutes and the status of your distribution will change from “In Progress” to “Deployed” in the CloudFront dashboard:

Amazon CloudFront Create Contribution

If you use your own CNAMEs please make sure to enter the domain in your domain management dashboard.

Amazon CloudFront enter your CNAME

Step 2: Configure Magento

The integration is really easy and takes about 3 minutes.

Go to Magento Backend -> System -> Configuration -> Web -> Unsecure

Magento CloudFront configuration

Go to Magento Backend -> System -> Configuration -> Web -> Secure

Magento CloudFront integration

What about updating the files when they change?

That’s a really good question. The files will expire from the network based on the expiration date (Cache control) when they were retrieved from the server.
How can i flush a single image or path?
I use the “Cloudfront Purge Tool” to purge files from Amazon Cloudfront.
It’s a little Chrome Extension.
This extension can be downloaded here: https://chrome.google.com/webstore/detail/gadbenpggeagjgnameagcpjnjdlckkpb

If you are familiar with the Amazon Api, you can write a little magento extension which purges the files automatically.

3 responses to Use Amazon CloudFront CDN to instantly improve the performance of your magento store

  1. Thanks for sharing, this is absolutely helpful information..
    Bucket Explorer Development Team Member. A tool to get working with all features of Amazon S3 and CloudFront.

  2. Thank you for this! We have implemented it on our site and it is working great!

  3. Ricardo Martins January 30, 2014 at 2:04 pm

    Very good article.
    Nathan, you dont need to upload files to cloudfront. Cloudfront downloads your static content from origin domain within the same path.

    For example:
    origin domain: mydomain.com
    alternate domain cname: static.mydomain.com

    After that, when you access for the first time http://static.mydomain.com/myfile.js cloudfront will download this file one time.

    Its really simple and useful.
    There are alternatives for Cloud Front, like Akamai for example.

Leave a Reply

*