Created
March 27, 2017 01:41
-
-
Save s-fujimoto/8ee846ed055ecc56ce356b3ff698c75b to your computer and use it in GitHub Desktop.
Approve CodePipeline approval action with Lambda function
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
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