5 Steps To Install Python Packages To AWS lambda From Windows OS

Phakorn Intassingha
3 min readJun 15, 2022

Hello everyone. Today, I’m gonna share my technique that is used to install python packages to AWS lambda. AWS lambda is a serverless computing service which means it allows users to run code without provisioning or managing infrastructure by putting any scripts to be a function in it such as Python, Java, Node.js, .NET, Ruby, etc. Lambda will be triggered from an event (CloudWatch log, CloudWatch Event, API Gateway, etc.). After completely executing the code Lambda will be stopped and wait for the next trigger (Pay only for the compute time).
For more information: https://aws.amazon.com/lambda/
Free tier: 1M requests per month

LET’S START

STEP 1: Create a new virtual python environment.

I recommend you to use PyCharm to create a new virtual environment.
New Project > named and locate the project location > Select Virtualenv > Mark Inherit global site-packages > Click Create button

STEP 2: Install the packages you want.

Open Terminal > Use pip install <YOUR PACKAGE==xx.xx> for control version > See what packages are installed

STEP 3: Zip the packages.

Navigate to [the project’s folder/venv/Lib/site-packages] > New folder named python > Copy the packages which are installed later to the python folder > Zip python folder

STEP 4: Create Lambda layer.

Navigate to the function you want to install the packages > Go to Layer menu > Click Create layer > Name your layer > Mark Upload a .zip file > Upload python.zip > Ensure compatible options are the same as a lambda function that you want to attach this layer.

STEP 5: Install the packages to Lambda Function.

Go to the function that you want to install the packages > scroll down click Add layer > Choose Custom layers > Enter the previously created layer > Click Add

Now, you can use the installed packages in your Lambda function!

Execution results when tableauserverclient is called

Best,
Phakorn Intassingha
Associate Data Analyst
LinkedIn: https://www.linkedin.com/in/phakorn-intassingha-6041b0194/

--

--