James Jones
James Jones

Reputation: 3899

Get name of Amazon Web Services Codecommit Repository in triggered Lambda function

I've created a trigger in my AWS CodeCommit repositories which runs a Lambda function whenever it is triggered. The Lambda function calls a script at my development server to perform a git pull. So far so good.

The problem is that I need to pass the name or ID of the repository that sets off the trigger to the dev machine so I can git pull the correct repository. My question then, is how do you call the name or id of the repository which triggered the Lambda function within the Lambda function?

My Lambda function is written in Python.

I've taken a look at the Lambda documentation at http://docs.aws.amazon.com/lambda/latest/dg/welcome.html but there is no mention of CodeCommit. This is probably because CodeCommit triggers are quite new - only a few months old. There is some documentation of event sources at http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html . I followed the tutorial at - http://docs.aws.amazon.com/codecommit/latest/userguide/how-to-notify-lambda.html to create the Lambda function.

Upvotes: 2

Views: 661

Answers (1)

Wade Matveyenko
Wade Matveyenko

Reputation: 4420

The code to pull out the repository is in the Python example. The code snippet is:

#Get the repository from the event and show its git clone URL
repository = event['Records'][0]['eventSourceARN'].split(':')[5]

The repository name is embedded in the ARN that the Lambda function receives.

Upvotes: 1

Related Questions