DEV Community

loading...
Cover image for handle AWS lambda function code on web with layers

handle AWS lambda function code on web with layers

yogeshnile profile image Yogesh Nile ・1 min read
  • When developer write AWS lambda function in python or other language than it require some libraries to run code and those libraries may be require more than 3 mb. AWS does not provide function editor on more than 3 mb code than it difficult to handle errors.
  • In this situation AWS provide layers to attach library and reusable those libraries in other lambda function. But if you create a layers in right way than lambda function throw the error. I wanna show to how to create a right layers using ec2 instance in python language.

ec2 instance must be give iam role to full access s3 bucket.

  • run below command on ec2 instance
sudo apt-get update
sudo apt-get install python3-pip -y
sudo apt-get install zip -y
sudo apt-get install awscli -y
mkdir -p build/python/lib/python3.8/site-packages
pip3 install <package> -t build/python/lib/python3.8/site-packages/ --system
cd build/
zip -r <zip name> .
aws s3 cp <zip file> s3://<bucket>
Enter fullscreen mode Exit fullscreen mode
  • goto s3 bucket and copy the zip file link
  • goto lambda console click layers
  • create layer input zip file link selete runtime and create.

  • congratulation you crated lambda layer sucessfully.

Discussion (0)

pic
Editor guide