Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I include packages in my aws lambda python deployement?

Matthias Leroy December 10, 2020

Hi,

I am trying to create a bitbucket pipeline to deploy my python code to AWS Lambda. My test function is very simple:

import pandas as pd
import numpy as np

def get_dashboard_url(event, context):
t = pd.DataFrame()

print(np.exp(2)) 

I managed to deploy the function but every time I run it I have an error: "No module named 'pandas'".

Here is my .yml file:

image: python:3.6
pipelines:
default:
- step:
name: Build and package
script:
- apt-get update && apt-get install -y zip
- mkdir packages
- pip install -r requirements.txt -t ./packages
- zip -r code.zip ./packages
- zip -g code.zip dashboard_url.py
artifacts:
- code.zip
- step:
name: Update Lambda code
script:
- pipe: atlassian/aws-lambda-deploy:0.2.1
variables:
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_DEFAULT_REGION: '*****'
FUNCTION_NAME: '*****'
COMMAND: 'update'
ZIP_FILE: 'code.zip'

 

I don't know what i am doing wrong

Thanks in advance for any help

 

Matthias

1 answer

0 votes
Halyna Berezovska
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 28, 2021

@Matthias Leroyyou install dependencies to packages folder , that your aws lambda function knows nothing about.

Your dependencies should be in the root.

My code has worked for me with your dependencies. See example:

script:
- apt-get update && apt-get install -y zip
- mkdir lambda_build
- cp lambda_function.py lambda_build/ && cd lambda_build
- pip install numpy pandas -t .
- zip -r code.zip . -x '*.pyc' -x '*__pycache__*'
artifacts:
- "lambda_build/code.zip"

Then put in the deploy section variable ZIP_FILE to "lambda_build/code.zip"

 

Regards, Galyna

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events