DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Tips for Optimizing Your Site for Multiple Browsers and Devices
  • ''Hey, Amazon! Where Is My Crop?'' How to Resize in The Cloud
  • Exploring Edge Computing: Delving Into Amazon and Facebook Use Cases
  • The Essentials of Amazon S3 Glacier for Affordable and Compliant Long-Term Data Archiving

Trending

  • How To Learn Secure Software Development Lifecycle (SDLC)
  • Architecting a Completely Private VPC Network and Automating the Deployment
  • Setting up Request Rate Limiting With NGINX Ingress
  • No Spark Streaming, No Problem
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Quickly add Amazon Cloudfront as a CDN

Quickly add Amazon Cloudfront as a CDN

Lorna Mitchell user avatar by
Lorna Mitchell
·
Jul. 16, 14 · Interview
Like (0)
Save
Tweet
Share
7.51K Views

Join the DZone community and get the full member experience.

Join For Free

Right now I'm working on an application which is experiencing lots of interest - and therefore lots of load! We needed to look at ways of trying to bring down the pressure on the servers, and decided to use a CDN (Content Delivery Network) for our image files. It was surprisingly painless to implement once I got into it so here it is in case it's helpful.

The way it works is that you point your image URLs to Amazon, and Amazon knows how to map those onto the images which continue to live where they are on your webserver and to be accessible by their own URLs. If Amazon gets a request for an image it doesn't have, it grabs it from your server and serves it - but then caches them all so the next request (or 10,000 requests!) will hit Amazon's servers and not yours. It also helps a bit because the domain is different and there is a limit on how many parallel requests browsers will make to any given domain, so you get more parallel requests on your page too.

Configurable Image Paths

I was able to switch out my image paths very easily because all images in the system had a path like $config['productImagePath'] - mostly this can help on dev platforms if they're not all the same, but also it helps if you need to move your images at a later date, as I had known could happen (and it did!). If this isn't already in place, you need to go find every image and make its URL configurable.

Set up Amazon Cloud Front

Head over to your Amazon Web Services console https://console.aws.amazon.com (it'll prompt you to sign up or log in as appropriate) and look for "Amazon CloudFront" in the "Storage" section.

Click the "create distribution" button and configure a few things:

  • Delivery method: web
  • Origin domain name: [domain where the images are served from right now]
  • Price class: choose which regions you need your images served from, it affects the cost

Then you need to wait for a few minutes while the cogs turn and it all gets created.

Testing Your Setup

You will get a URL for your CloudFront that looks like http://uttergobbledegook.cloudfront.net and you use that in place of the source domain you set earlier. So if your images were at http://mygreatsite.com/product_images/whisk.jpg now you should be able to request http://uttergobbledegook.cloudfront.net/product_images/whisk.jpg in your browser. Once it's cached, the response time should be very quick too.

Now go back and where your configuration settings once pointed to a URL on your own site, they will now point to the path under the CloudFront domain ... you probably need different distributions for your various staging/live platforms, and these can be enabled and disabled differently.

I found this was a very painless way of getting a CDN into place - no changes to the development platforms, minor config changes to the staging/live platforms, and the images stay in the same place that they always lived!

Whatever Next?

There are actually a few things you can do from here:

  • Use a cname alias to make a nicer URL such as http://static.mygreatsite.com
  • Tweak the caching rules to make sure they make sense for your application, they are very VERY configurable
  • If the images you're serving are assets rather than upload files, consider deploying them straight to S3 and setting up your CloudFront to server from there

Did this work for you? What did I miss? And did Amazon update their interface since I wrote this post (this happens often). Please leave a comment :)

CloudFront Content delivery network Amazon Web Services

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Tips for Optimizing Your Site for Multiple Browsers and Devices
  • ''Hey, Amazon! Where Is My Crop?'' How to Resize in The Cloud
  • Exploring Edge Computing: Delving Into Amazon and Facebook Use Cases
  • The Essentials of Amazon S3 Glacier for Affordable and Compliant Long-Term Data Archiving

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: