Created
June 7, 2016 23:56
-
-
Save melalj/44e575b1ae9483df787e341e5e3c5420 to your computer and use it in GitHub Desktop.
Shell command to Invalidate Cloudfront assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
AWSACCESS="AWSACCESS" | |
AWSSECRET="AWSSECRET" | |
DISTRIBUTION_ID="DISTRIBUTION_ID" | |
PATH="/path_to_invalidate" | |
AWSDATE=`/usr/bin/php -r "echo gmdate('D, d M Y G:i:s T');"` | |
AWSSIG=`/usr/bin/php -r "echo base64_encode(hash_hmac('sha1', '$AWSDATE', '$AWSSECRET', true));"` | |
EPOCH=`/usr/bin/php -r "echo gmdate('U');"` | |
XML="<InvalidationBatch><Path>$PATH</Path><CallerReference>$DISTRIBUTION_ID$EPOCH</CallerReference></InvalidationBatch>" | |
/usr/bin/curl -X POST -H "Authorization: AWS $AWSACCESS:$AWSSIG" -H "Date: $AWSDATE" -H "Content-Type: text/xml; charset=UTF-8" -d "$XML" https://cloudfront.amazonaws.com/2010-11-01/distribution/$DISTRIBUTION_ID/invalidation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment