How I Write Meaningful Tests for AWS Lambda Functions

How I Write Meaningful Tests for AWS Lambda Functions

An attempt to rid the world of “assert True = True” forever. A Harsh Truth If you are going to write meaningless unit tests that are more likely to mask errors than expose them, you are better off skipping the exercise altogether.

A Harsh Truth

If you are going to write meaningless unit tests that are more likely to mask errors than expose them, you are better off skipping the exercise altogether.

There, I said it.

Your time is precious and could be spent on better things than achieving a hollow coverage percentage.


Effective testing of code has long been a challenging problem in programming, and newer tools like AWS Lambda seem to bring out the worst in developers when it comes to writing tests.

I think the main reason for this is that it’s more difficult (or at least less intuitive) to mirror the Lambda production environment locally. And as a result, some developers choose to abstain from any local testing entirely.

I know because I’ve done it myself, even for projects in production. Instead, testing was done integration-style only after code was already deployed to the cloud.

This is extremely manual and wastes time in the long run.

Another approach I’ve seen results in tests that look something like this:

This is the unmistakeable sign of an engineering team with a test coverage requirement but a lack of accountability. And no explanation is needed that the above is a no-no.

So, how do we go about transforming the sad test_lambda_function.py file above into something meaningful?


Before we can dive right into testing our Lambda code, there are a couple hurdles in the way. We’ll cover each of these individually and determine how to best handle them. Once dealt with, we are then free to test Lambdas to our heart’s content!

Note: I’ll be including small snippets of code throughout the article for clarity. But at the end there will be a full working code example to reference.

programming aws data-engineering serverless python

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Python Programming & Data Handling

Python Programming & Data Handling

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Serverless COVID-19 Data Scraper with Python and AWS Lambda

Step-by-Step Tutorial: Scheduling your Python Script with AWS Lambda

Data Science With Python Training | Python Data Science Course | Intellipaat

🔵 Intellipaat Data Science with Python course: https://intellipaat.com/python-for-data-science-training/In this Data Science With Python Training video, you...

Managing Data as a Data Engineer:  Understanding Data Changes

Understand how data changes in a fast growing company makes working with data challenging. In the last article, we looked at how users view data and the challenges they face while using data.