15.02.2024

Lambda

I have been itching to get into AWS Lambda for a while. I enjoy the concept of on-demand compute, since my projects usually have little traffic and only get used sporadically. It's much more economical to use Lambda instead of persistent containers in ECS in those cases.

Local Development

I dabbled into Lambda in the past, but I had issues setting up my local development environment. Since lambdas require custom events, in my case HTTP events provided by an API Gateway, I can't simply run it locally. Where am I supposed to get the AWS specific events from? After some tinkering, I have found a setup that I am happy with.

I use aws-lambda-go-api-proxy to start my api locally. It's exposed like any other http api and I can call it via curl or the browser. When deployed, the proxy handles the events from aws and forwards them to my router. This way I have zero additional effort when developing locally and can deploy without any special workflows.

Deployment

I chose to deploy my lambda using a docker container. I could have also zip'd the binary and uploaded that. But with the docker container I get built in version management and don't have to think about where my zip archives live. I just push to the aws container registry and then select the revision in my lambda. I additionally have an api gateway provisioned, which creates the entrypoint to my application. I add a CNAME record to my dns provider and voila, it's all done.

The result can be seen here: paste.fdm.com.de
Repository: https://github.com/m4tthewDE/paste