Motivation Link to heading

As a developer who loves to tinker and create personal applications. One way I am to do that is with serverless.

AWS has a good offering with AWS lambda where you can create the following

  • APIs with AWS lambda and API gateway
  • Cronjobs with AWS lambda and Eventbridge
  • Workflows with AWS lambda and Stepfunctions

My motivation for this post is to showcase how to create a simple AWS Golang lambda. The example will be a Hello world but will contain

  • setup scripts to build and delete artifacts
  • terraform code to create and destroy infra as needed
  • golang script

Steps Link to heading

You can use this repo as a reference or clone to follow along https://github.com/darrylbalderas/lambGo.

  1. Clone this repo https://github.com/darrylbalderas/lambGo
  2. Run make build. This will create golang binary and try to create aws lambda infra like iam role, iam policy, cloudwatchlog group, and lambda function
  3. Once terraform has finished applying. You can Run make invoke to invoke newly create function. You should see
{"Message":"Hello Maya!"}
  1. You are done! It was quick and painless.

Learnings Link to heading

Learnings that I got from doing this small project was seeing how simple and fast creating a golang lambda. I usually create my lambdas using python. I will most likely switch for the follwoing reasons

  • AWS supports newer versions of golang without me specifying versions
  • Creating tests is easier and I don’t have to worry about not including them in my archive file
  • Benefits of a static type language
  • Go provides the ability to provided structure events. So no more nested dictionaries in my code :)