Giter Site home page Giter Site logo

jmoratilla / aws-cloudfront-auto-invalidator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from funyholic/aws-cloudfront-auto-invalidator

0.0 0.0 0.0 7 KB

AWS SAM solution to automatically invalidate content in a cloudfront distribution based on S3 update events

License: MIT License

Shell 52.41% Python 47.59%

aws-cloudfront-auto-invalidator's Introduction

aws-cloudfront-auto-invalidator

This is a small Lambda function (packaged somewhat with AWS SAM) to auto-invalidate content in Cloudfront when the underlying S3 origin content changes.

Requirements

  • AWS CLI (configured with at least one profile)
  • AWS SAM CLI
  • Existing S3 bucket to store SAM Lambda code
  • Existing S3 bucket and Cloudfront distribution

Deploying

Invoke the deploy.sh script in the root of the project as follows:

deploy.sh ALL|NEW_SUB <bucket for lambda code> <origin bucket> <AWS CLI profile name>

If ALL is specified as the first argument, the function will be packaged, deployed and a new event subscription will be created for the specified origin bucket. If NEW_SUB is supplied, only a new event subscription from an origin bucket will be added (ie. use this to subscribe multiple buckets to the single function)

Deployment Notes

Ideally, all of this solution would be a small, self-contained SAM application. But due to this issue, SAM cannot subscribe events to pre-existing buckets. Therefore, the deploy script has to add the Lambda permissions and S3 event subscription after the function has been created. This is all performed using the AWS CLI in the deploy.sh script.

Want to monitor multiple buckets? Just run deploy.sh with a different origin bucket (parameter 2). You'll get a different event subscription to the Lambda function.

Running locally

The function can be executed locally using the SAM CLI and the SampleEvent.json in the project. You will need Docker installed to enable local execution via SAM

sam local invoke --event SampleEvent.json

This will invoke your function and pass it the contents of SampleEvent.json. You will need to modify SampleEvent.json to represent a valid S3 bucket.

aws-cloudfront-auto-invalidator's People

Contributors

dnorth98 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.