Webhooks with CodeCommit & AWS λ

Categories Guides , ,

AWS CodeCommit is an excellent service for privately storing Git managed source-code. Although webhooks are not an in-built feature, you can setup a reusable Lambda Function for this purpose.

  • The Lambda illustrated below can trigger POST webhooks after Git pushes to CodeCommit.
  • You should already have a CodeCommit repo created before starting this guide.

Creating the Lambda Function

From the AWS Console navigate to Lambda » New function

Blueprint » Blank Function

  • Skip adding a trigger for now, just click  on the screen that appears.

Configure the function

Function code

GitHub Gist

  • No need for encryption helpers or environment variables.

Function handler and role

  • Leave policy templates empty.
  • No changes necessary to Advanced settings.
  • Click 

Create and confirm

 » 

Adding a Trigger for your CodeCommit Repository

Triggers » [Add trigger]

Trigger type

Repository and webhook

  • Push to existing branch is not the default option, you’ll have to change it
  • Use the Custom data field for your POST URL

» Create and confirm

  » 

  • Repeat the same procedure for future repositories, using the same Lambda function.

Price considerations

The Lambda free tier …  is available to both existing and new AWS customers indefinitely. 1

This function runs on average 500ms with the free tier including 3,200,000 seconds as of this writing. So you could trigger 6 million webhooks in a given month without incurring any additional AWS costs.

References

  1. https://aws.amazon.com/lambda/pricing/