How To Create Lambda Layer (2 Min) | AWS | Package Python Libraries For Lambda Functions

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ส.ค. 2024
  • In this tutorial, you'll learn how to create a lambda layer to package libraries and other dependencies that you can use with your AWS Lambda functions. Using layers reduces the size of uploaded deployment archives and makes it faster to deploy your code.
    docs.aws.amazon.com/lambda/la...
    -
    Facebook: / gokcedbsql
    -
    Video Transcript:
    -
    Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to add a Python Lambda Layer in AWS. Let's start by navigating to the Lambda service then click on create function and give it a name.
    Select Python for runtime then hit create function. In the code Source section, I'm going to copy and paste pre-written Python code that imports the request Library. On lines 5 and 6, I'm grabbing the HTML text from gokcedb.com and printing it out on the console.
    Hit deploy then click on test and give your test event a name then hit save. Click on test again to execute your Lambda function and you should receive an error message saying unable to import module name requests. To fix this error, we're going to create a Lambda layer.
    I'm going to copy and paste the virtual environment folder from an existing project which has the requests package installed already. Let's rename this folder to Python which is the requirement according to this AWS guide. Feel free to remove any unnecessary folders or libraries that you don't need in this layer.
    Right-click on the Python folder and hit compress to create a Python.zip file. Let's go back to the Lambda console then click on layers in the left menu then hit create a layer. Give your layer a name then upload the Python.zip file that we just created.
    Select comparable architectures and runtimes then hit create. Now go back to your Lambda function then click on layers in the function overview section. Click on add a layer button then choose custom layers.
    Choose the custom layer that we just created then hit add. Click on the test button and this time your Lambda function should execute without any errors. As you can see the HTML was printed on the console.
    There you have it. Make sure you like, subscribe, and turn on the notification bell. Until next time.

ความคิดเห็น • 26

  • @user-tv8bo1cp9p
    @user-tv8bo1cp9p 11 หลายเดือนก่อน +5

    Thanks so much! Spent forever trying to find out how to do this.Very helpful.

    • @GokceDB
      @GokceDB  11 หลายเดือนก่อน

      Glad I could help!

  • @user-qv6fe6us6y
    @user-qv6fe6us6y 6 หลายเดือนก่อน +1

    Thanks, this video solved my issue of import error after trying a lot many. Thanks bhai

  • @dhirajkumarsahu999
    @dhirajkumarsahu999 หลายเดือนก่อน

    Thanks a lot for this short and to the point video, subscribed!

  • @joseluismorillospinedo8648
    @joseluismorillospinedo8648 2 หลายเดือนก่อน

    Very useful! Thanks a lot!

  • @russellcastagnaro72
    @russellcastagnaro72 9 หลายเดือนก่อน +2

    Thanks, this really helped!!!

    • @GokceDB
      @GokceDB  9 หลายเดือนก่อน

      Glad it helped!

  • @ArniFuentes
    @ArniFuentes หลายเดือนก่อน

    thank for the tutorial

  • @user-vz1df9ub4v
    @user-vz1df9ub4v 11 หลายเดือนก่อน +2

    bro thank you, spend two days, getting work with pandas, finally run it using layers

    • @GokceDB
      @GokceDB  11 หลายเดือนก่อน +1

      great!

    • @shomiksingh5929
      @shomiksingh5929 10 หลายเดือนก่อน +2

      How did you call the lambda layer from another lambda function?

    • @GokceDB
      @GokceDB  10 หลายเดือนก่อน +1

      @@shomiksingh5929 check this video: th-cam.com/video/nElDfGVgvy4/w-d-xo.html

  • @tiagoprelato4220
    @tiagoprelato4220 5 หลายเดือนก่อน

    Hey Gokce! Thank you very much for the tutorial. Do you know what are the options when yours layers consume more than the limit?

  • @nadunovitigla109
    @nadunovitigla109 2 หลายเดือนก่อน

    thank you

  • @manikandannp
    @manikandannp 2 หลายเดือนก่อน

    I have a Question. Once we make a webhook (in my case its webex). For any reason I happen to delete and re-create a new one, would that affect my message to be pushed to AWS Lambda? Should I be making any changes to code-base or aws service when I change/ delete webhook id

  • @GokceDB
    @GokceDB  11 หลายเดือนก่อน

    Updated tutorial can be found here: th-cam.com/video/nElDfGVgvy4/w-d-xo.html

  • @shekelboi
    @shekelboi 3 หลายเดือนก่อน

    Really useful, it's a pitty on Windows you need to rename the Lib folder and create a new folder inside it, to get it working.

    • @shekelboi
      @shekelboi 3 หลายเดือนก่อน

      A cool workaround I found was creating a requirements.txt then installing all the packages from that in the python directory:
      pip freeze > requirements.txt
      pip install -r requirements.txt -t python

    • @mistromoves
      @mistromoves หลายเดือนก่อน

      @@shekelboi Hey what do you mean by this? I'm using windows and I'm trying to do the work around and I can't get it to work

    • @shekelboi
      @shekelboi หลายเดือนก่อน

      @@mistromoves If you run those two commands it should install the packages in the appropriate (python) folder and from there you just need to zip it up and upload it. Let me know where you're stuck so I can help.

  • @user-cx6cc5wh7o
    @user-cx6cc5wh7o 7 หลายเดือนก่อน

    @Abi Asija What if the zip file is around 0.3Gb size? AWS returns error: Failed to create layer version: Unzipped size must be smaller than 262144000 bytes.
    Any idea how to deal with it? Thank you

    • @e.zarate
      @e.zarate 5 หลายเดือนก่อน

      Maybe create multiple layers than don't exceed the limit or reduce the zip size.

    • @ragul_surya
      @ragul_surya 8 วันที่ผ่านมา

      Did u get any solution?

  • @mikecmw8492
    @mikecmw8492 26 วันที่ผ่านมา

    No one creates layers like this. Show how to do it from cmd line

  • @ManojKumar-zn2gf
    @ManojKumar-zn2gf 10 หลายเดือนก่อน +1

    Thanks for the video, it was very clear and precise, In the same way, I wanted to use the azure-identity package with my aws lambda function so for that purpose I created a directory and installed the azure-identity package using the pip command then converted it into a zip file and uploaded it to AWS lambda function along with function.py file. When I ran the script I got the import error stating that
    Error Message: {
    "errorMessage": "Unable to import module 'lambda_function': cannot import name 'x509' from 'cryptography.hazmat.bindings._rust' (unknown location)",
    "errorType": "Runtime.ImportModuleError",
    "requestId": "3e17800f-0330-40f5-af54-69d860fbfdc1",
    "stackTrace": []
    } which is the dependent package for the azure-identity package. I would be grateful if you could please help me on how to fix this issue.

    • @GokceDB
      @GokceDB  10 หลายเดือนก่อน

      See if this helps: stackoverflow.com/questions/75757846/aws-lambda-runtime-import-module-error-cannot-import-name-x509-from-crypto