Create A Deployment Package
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.
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
# get inside the directory
# install pymysql module
pip install pymysql -t .
# create a zip file using installed module
zip -r9 ../pymysql.zip .
# get to the parent directory
# create lambda_function.py with lambda function definition
# 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.
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.
Step 4: Check CloudWatch Logs.
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