Python custom runtime for Lambda function

0

Hi all! I am trying to create a custom Python 3.8 runtime for my Lambda function and uploading it as a .zip file (and not through docker image). However, I've encountered an issue where the resulting .zip file, which includes the Python 3.8 version, the bootstrap file, and the handler.py, is nearly 100MB in size. Unfortunately, Lambda functions can only handle .zip files with a maximum size of 50MB.

I've attempted to reduce the size by removing certain files and folders from the Python directory, but I haven't had any success in achieving the desired size reduction. Therefore, my question is whether any of you have experience creating a custom Python runtime and successfully uploading it as a .zip file to a Lambda function. If so, could you please share the steps and instructions you followed to achieve this? Thank you in advance for you help.

xnikmim
已提问 7 个月前466 查看次数
2 回答
0

Hi, the Lambda Developer Guide shows that if a .zip file larger than 50 MB, you must upload the .zip file to S3, and specify its URL when you deploy the function.

https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-zip.html#configuration-function-update

If the .zip file archive is smaller than 50 MB, you can upload the .zip file archive from your local machine. If the file is larger than 50 MB, upload the file to the function from an Amazon S3 bucket.

Also note that the extracted .zip file cannot exceed 250 MB.

profile picture
HS
已回答 7 个月前
  • Hello, and I appreciate your prompt response. I've previously attempted the solution you suggested. However, the problem persists because the Python version I've installed is approximately 400MB. Consequently, I encounter the error you described, which states, "Unzipped size must be smaller than 262144000 bytes." Given this constraint, I'm wondering if there might be an alternative approach?

  • because the Python version I've installed is approximately 400MB

    Unfortunately .zip archive deployment is not feasible in this case since the 250 MB quota applies to layers and custom runtimes as well. (Note that this quota cannot be increased)

    50 MB (zipped, for direct upload)

    250 MB (unzipped)

    This quota applies to all the files you upload, including layers and custom runtimes.

    Container image size accepts up to 10 GB size, so it should be the only choice for you Lambda deployment.

  • can you share your use case. cuz I see that the limitation you mentioned can be neglected if you use docker image. And that you specifically mentioned that you are not using Docker Image. If you could provide me with why is that I can better help with it.

0

Hello,

You may want to look at using Lambda layers. One of the benefits of using layers is to reduce the size of your deployment packages. https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html

Sharing a tutorial link as well which shows how to publish custom runtime with layers https://docs.aws.amazon.com/lambda/latest/dg/runtimes-walkthrough.html#runtimes-walkthrough-function

Hope this fits your use case.

AWS
已回答 7 个月前
profile picture
专家
已审核 7 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则