Created
May 31, 2017 22:01
-
-
Save dstokes/c639be0b21690c840052c2bd9653d4b6 to your computer and use it in GitHub Desktop.
Github to Codebuild 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, json | |
def lambda_handler(event, context): | |
client = boto3.client('codebuild') | |
for e in event['Records']: | |
source = e['EventSource'] | |
if source == 'aws:sns': | |
message = json.loads(e['Sns']['Message']) | |
project = message['repository']['name'] | |
treeish = message['ref'].replace('refs/heads/', '') | |
sha = message['after'] | |
print(treeish, sha) | |
response = client.start_build( | |
projectName=project, | |
sourceVersion=sha | |
) | |
print(response) | |
else: | |
print("Unrecognized event source: {}".format(source)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment