Skip to content

Instantly share code, notes, and snippets.

@s-fujimoto
Created March 27, 2017 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-fujimoto/8ee846ed055ecc56ce356b3ff698c75b to your computer and use it in GitHub Desktop.
Save s-fujimoto/8ee846ed055ecc56ce356b3ff698c75b to your computer and use it in GitHub Desktop.
Approve CodePipeline approval action with Lambda function
import boto3
def lambda_handler(event, context):
pipeline_name=event['PIPELINE_NAME']
stage_name=event['STAGE_NAME']
action_name=event['ACTION_NAME']
cp = boto3.client('codepipeline')
state = cp.get_pipeline_state(name=pipeline_name)
for stage_state in state['stageStates']:
if stage_state['stageName'] == stage_name:
stage = stage_state
for action_state in stage['actionStates']:
if action_state['actionName'] == action_name:
action = action_state
token = action['latestExecution']['token']
cp.put_approval_result(
pipelineName=pipeline_name,
stageName=stage_name,
actionName=action_name,
result={
'summary': 'ok',
'status': 'Approved'
},
token=token
)
return 'Completed.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment