Create A Deployment Package

Create A Deployment Package

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed layers in a lambda function. We have also created a layer for python package pymysql and used that package in our lambda function.

https://cloudaffaire.com/lambda-function-layers/

In this blog post, we will create a deployment package for our lambda function containing our function definition along with the dependent package. The function definition and package are the same as the previous post, only we are deploying the package directly within the function instead of using layers.

Create A Deployment Package

Step 1: Login to EC2 instance and create the deployment package

# create module directory
mkdir pymysql

# get inside the directory
cd pymysql

# install pymysql module
pip install pymysql -t .

# create a zip file using installed module
zip -r9 ../pymysql.zip .

# get to the parent directory
cd ..

# create lambda_function.py with lambda function definition
vi lambda_function.py

# include lambda_function.py in the pymysql.zip
zip -g pymysql.zip lambda_function.py

# update the existing function using AWS CLI
aws lambda update-function-code --function-name myfunction --zip-file fileb://pymysql.zip

Step 2: Login to AWS console and check your function definition.

Create A Deployment Package

Observe: Lambda function successfully updated with the deployment package containing pymysql package along with lambda_function.py.

Step 3: Test the function by uploading an object into the S3 bucket.

Create A Deployment Package

Step 4: Check CloudWatch Logs.

Create A Deployment Package

Observe: Our lambda function with module pymysql successfully executed.

Hope you have enjoyed this article. In the next blog post, we will execute the lambda function from the AWS console.

To get more details on Lambda, please refer below AWS documentation

https://docs.aws.amazon.com/lambda/index.html

 

Leave a Reply

Close Menu