How I deploy aws golang lambdas with terraform
These days I’m a bit of a fanboy when it comes to Golang and Terraform, so it’s completely natural that I wanted to make the two play nice together when deploying to AWS Lambda. Which is what I did.
I’ve played around with tools such as Serverless Framework, but I decided would rather do it all in Terraform as Cloudformation (which Serverless Framework utilises when deploying to AWS) is slower and with many limitations. Plus, I think it’s good to use fewer tools where possible.
Most recently, I decided to write a Terraform module that makes an AWS Eventbridge catchall rule for a given service, which triggers a Golang Lambda function that logs the triggering event as json.
The motivation behind this was to be able to deploy infrastructure that can log the events created by the specified service quickly for reference later. This is a developer experience improvement for me as the documentation is spotty to non-existent depending on the service (e.g. aws backup ) and it’s impossible to create logic based on Eventbridge events without documented events.
The code for this module is used as an example in this post, and is located in this Github repo: https://github.com/seanturner026/terraform-module-eventbridge-debug-logger