Skip to content

Instantly share code, notes, and snippets.

@MrHassanMurtaza
Last active January 10, 2020 12:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrHassanMurtaza/e52ee0b565c4aabbef5f531872021b8f to your computer and use it in GitHub Desktop.
Save MrHassanMurtaza/e52ee0b565c4aabbef5f531872021b8f to your computer and use it in GitHub Desktop.
AWS CodePipeline Executor Python
import json, os
import boto3
from botocore.exceptions import ClientError
def lambda_handler(event, context):
"""
Lambda Handler
Triggers AWS CodePipeline
:param event: takes event triggered by cloudwatch rule
"""
client = boto3.client('codepipeline')
# pipeline from lambda env
pipeline = os.environ['CODE_PIPELINE']
try:
response = client.start_pipeline_execution(
name = pipeline
)
return {
'statusCode': 200,
'body': json.dumps(f'Pipeline executed successfully with message {response}')
}
except ClientError as e:
raise Exception(f'Pipeline executed with error {e}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment