Last active
January 10, 2020 12:40
-
-
Save MrHassanMurtaza/e52ee0b565c4aabbef5f531872021b8f to your computer and use it in GitHub Desktop.
AWS CodePipeline Executor Python
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 characters
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