CloudFront Invalidate Distribution
Make your AWS CodePipeline invoke this Lambda function to invalidate a CloudFront distribution.
Install the Serverless Framework if you don't have it.
npm install -g serverless
git clone https://github.com/jweyrich/cloudfront-invalidate-dist.git
cd cloudfront-invalidate-dist
serverless deploy [--aws-profile yourProfile]
-
Open your CodePipeline
-
Create a new stage
-
Add a new action
-
In 'Action Provider' select 'AWS Lambda'
-
In 'Function name' select the deployed function
-
In 'User parameters' specify the desired CloudFront distribution and paths to be invalidated. Example:
{ "distributionId": "FP7AWS1WBJLKSX", "objectPaths": [ "/*" ] }
-
Save the action
-
Test
{ "distributionId": "FP7AWS1WBJLKSX", "objectPaths": [ "/*" ] }
{ "distributionId": "FP7AWS1WBJLKSX", "objectPaths": [ "/foo", "/bar/baz.jpg", "/bar/baz/*" ] }