Tuesday 11 May 2021

Creating And Using Lambda Layer in AWS Lambda

You can find how to create a lambda function using EC2 here. Once the deployment package is created and placed in S3 in the bucket.

STEPS TO CREATE LAMBDA LAYER:

Below are the steps to create a lambda layer in AWS.

1) Navigate to Lamdba and choose Layers from Dashboard.

Lambda Layer
Lambda Layer

2) Choose create the layer, mention the layer name, description, Runtimes and select “Upload a file from Amazon S3” and click create. You can also upload the zip file directly from the remote, but the zip file size should be less than 10 MB.

Options to upload Zip file
Options to upload Zip file

3) Click create and copy the ARN of the lambda layer. You can create another version by 'CREATE VERSION' at the top right corner of the Lambda Layer page, by following the same steps as above.

Lambda Layer
Lambda Layer


HOW TO USE LAMBDA LAYER IN LAMBDA FUNCTION:

Below are the steps to add the lambda layer in the desired lambda function.

·    1) Go to the desired lambda function. Click on the Layers and choose the “Add a layer” option.

Add a layer - AWS Lambda
Add a layer - AWS Lambda

2) 
 After that choose “Specify an ARN” option and paste the ARN of the desired lambda layer.

Choose a layer - AWS Lambda
Choose a layer - AWS Lambda

3) 
Click “ADD” and now run the lambda function.

If Below might the error that you may face while using the lambda layer in a function.

    ERROR MESSAGE: No module found

    SOLUTION: Probably because your deployment package doesn't have a proper structure. 

Lambda Layer Structure
Lambda Layer Structure

   ERROR MESSAGE: Task timed out after 3.00 seconds

    SOLUTION: Increase the timeout period, you can increase it up to 15 mins it is under the configuration tab.

Configuration - AWS Lambda
Configuration - AWS Lambda

1 comment: