Created
October 2, 2022 06:13
-
-
Save deepak7093/6d9f9502c4ed6bb0e207c5a59c222ae0 to your computer and use it in GitHub Desktop.
Revisions
-
deepak7093 created this gist
Oct 2, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import json import boto3 code_pipeline = boto3.client("codepipeline") cloud_front = boto3.client("cloudfront") def lambda_handler(event, context): job_id = event["CodePipeline.job"]["id"] try: user_params = json.loads( event["CodePipeline.job"] ["data"] ["actionConfiguration"] ["configuration"] ["UserParameters"] ) cloud_front.create_invalidation( DistributionId=user_params["distributionId"], InvalidationBatch={ "Paths": { "Quantity": len(user_params["objectPaths"]), "Items": user_params["objectPaths"], }, "CallerReference": event["CodePipeline.job"]["id"], }, ) except Exception as e: code_pipeline.put_job_failure_result( jobId=job_id, failureDetails={ "type": "JobFailed", "message": str(e), }, ) else: code_pipeline.put_job_success_result( jobId=job_id, )