Member-only story

Creating a Python OpenCV Layer for AWS Lambda

A simple approach to creating an AWS Lambda layer for Python’s OpenCV wrapper

Paulo Carvalho
Better Programming
3 min readJan 15, 2021

Coding desk setup
Photo by Farzad on Unsplash.

Lambda is a serverless offering by AWS that enables running scalable code without needing to configure servers. Each Lambda environment (corresponding to different versions of the compatible languages) comes with a selection of packages pre-installed.

However, what happens when we require a package that is not provided? There are a few approaches to addressing this shortcoming, one of which is the use of a Lambda layer.

In the next section, we will go over a programmatic solution to create a Lambda layer for a Python 3.7 application that requires OpenCV.

1. Install the Library in a Compatible OS

Lambda functions run on Amazon Linux (AMI). Therefore, to ensure that our version of OpenCV will run on the Lambda, we need to compile it for AMI. One way to do this is to install the library on an EC2 instance.

However, for expediency, we will use Docker. The Dockerfile below creates a Docker image with OpenCV installed:

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

Paulo Carvalho
Paulo Carvalho

Written by Paulo Carvalho

Want to chat about startups, consulting or engineering? Just send me an email on paulo@avantsoft.com.br.

Responses (1)

Write a response