Monday 10 May 2021

Creating Lambda Deployment Package Using EC2

Lambda Layers: 

An archive containing additional code, such as libraries, dependencies, or even custom runtimes. When you include a layer in a function, the contents are extracted to the /opt directory in the execution environment.

Run the commands mentioned below to create the package for lambda layers in the EC2 server.

The Lambda Layer you are creating should have the below structure or else will get the error message “No module found” while importing the module in lambda function.

Lambda Layer Structure
Lambda Layer Structure

STEPS TO CREATE PACKAGE FOR LAMBDA LAYER:

  1. Create a folder structure as below to install the package for desired modules. 

    mkdir -p build/python/lib/python3.6/site-packages
    

  2. Below three commands are to select the python version to install the modules and to install pip3. (Optional) 

    ls usr/bin/python*
    sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python3.6 1
    sudo update-alternatives --config python3
    sudo apt install python3-pip
    

  3. This command is to install the desired module in the targeted folder. Here I am installing Pandas and xlrd.  

    pip3 install pandas xlrd -t build/python/lib/python3.6/site-packages/ --system
    

    Below commands are to create the zip file for the lambda layer package. 
     

    cd build/
    zip -r9 Python3.6_Pandas_Lib.zip *
    

    That's it now the deployment package is ready. Copy the zip file to the S3 bucket.
--------------------------------------------------------------------------------------------------------------
Here are some other posts that might be helpful :

No comments:

Post a Comment