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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ