Skip to content

Instantly share code, notes, and snippets.

@dstokes
Created May 31, 2017 22:01
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 dstokes/c639be0b21690c840052c2bd9653d4b6 to your computer and use it in GitHub Desktop.
Save dstokes/c639be0b21690c840052c2bd9653d4b6 to your computer and use it in GitHub Desktop.
Github to Codebuild Lambda Function
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