Sitemap
Better Programming

Advice for programmers.

Follow publication

Member-only story

Simple Serverless: Neat and Tidy Lambda Functions Use Powertools

6 min readNov 13, 2020
Powertool in action
Photo by Christopher Burns on Unsplash.

Every Lambda function I write starts in the same way: a bunch of code to unpack the event and then validate its contents. Sound familiar?

Moreover, I can never remember the exact key names for certain event payloads. How do I get the headers from an ApiGateway event again? Is it headers or Headers?

Oh right, it’s headers and multiValueHeaders. Of course it is.

So each new Lambda function I create starts off in a very similar way to every other Lambda function I create:

  • Googling for event payload structures.
  • Unpacking the contents and calling json.loadsto turn strings into dicts.
  • Validating the contents.

My First Idea

Attaining great heights
Photo by the author.

The more frustrated I got with writing and rewriting this kind of code, the more motivated I got to find a better way. So I resorted to writing helper libraries. Here’s an example of an ApiRequest:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Greg Farrow
Greg Farrow

Written by Greg Farrow

Principal Engineer. I 💛 Serverless

No responses yet

Write a response