images
How-To Guides

Automatically trigger CDN purge on S3 change

Shalom Carmel, CIO @ GlobalDots
19.04.2022
image 2 Min read
Content Delivery Network (CDN)

A CDN requires an origin server, which can be a S3 bucket. s3-trigger-purge-cdn are python scripts that run as Lambda functions, and are triggered by file uploads to the bucket. Once triggered, the Lambda function will attempt to purge the old file from the CDN cache. Currently supported CDN vendors:

  • Akamai
  • Cloudflare
  • Edgecast
  • Fastly
  • Highwinds

Standalone Legacy mode

  • Edgecast
  • Akamai
  • Highwinds

While I started as a project with separate parts for each CDN vendor, the standalone parts will not be maintained anymore.

Features:

  • Python based: Easy to set up and maintain
  • Uses Lambda environment variables: Modify the environment variables to modify the Lambda behavior
  • purge or load: On Edgecast, you can decide whether to purge from the edge or load onto the edge

Environment variables

Environment variables will be loaded only at the Lambda cold start

  • debug <true|false>
  • config_file defaults to multicdn.config.yml

General Usage

  1. Install and configure Python, pip and Boto3
  2. In the project directory, run the following command: pip install -r requirements.txt -t . This is in order to be able to create a full deployable package for Lambda
  3. Update the config files. There is a master YAML file, but credentials can also be managed in the config.py files in each vendor’s folder.
  4. Run the installation script. It will upload the function and its dependencies to AWS Lambda, as well as create the necessary roles, policies and triggers.

Additional Notes

Creating an Edgecast API key: https://support.globaldots.com/hc/en-us/articles/115004003749-Edgecast-Allowing-API-access

Adding authentication to Fastly purge: https://docs.fastly.com/guides/purging/authenticating-api-purge-requests

Good luck!

Comments

0 comments

There’s more to see

Old Dogs, New Tricks: Innovating with CDNs
Content Delivery Network (CDN)
Dror Arie, Senior Solutions Architect @ GlobalDots 20.04.22

Today’s digital businesses with global customers cannot afford slow page loads and applications caused by physical distance and latency issues. Page load speeds can have a significant effect on customer acquisition and retention. Walmart discovered that a 1% increase in page load time results in a 2% increase in conversion rates. So businesses are using […]

Read more
Single vs. Multi CDN: Pros, Cons, Technical & Operational Considerations
Content Delivery Network (CDN)
Miguel Fersen, Senior Cloud Consultant @ GlobalDots 18.04.22

CDNs are crucial for user experience and your reputation Being around for a long time, CDNs are now an essential part of modern Internet service. A CDN helps a content owner deliver content at high speeds. This is done as a distributed system, where different servers are deployed in different datacenters worldwide and share the […]

Read more
5 Reasons to Use jQuery CDN in Your Website
Content Delivery Network (CDN)
Shalom Carmel, CIO @ GlobalDots 10.01.22

Many different programming languages have emerged throughout computer programming and capabilities. However, some are more useful and dynamic than others: jQuery CDN is one of the most useful languages to learn and implement. A JavaScript library, such as jQuery CDN, is a collection of pre-written code. Instead of writing their code, web and application developers […]

Read more
Unlock Your Cloud Potential
Schedule a call with our experts. Discover new technology and get recommendations to improve your performance.
Contact us