How do the lambda function and lambda layers quotas work?

0

I see that the docs state:

50 MB (zipped, when uploaded through the Lambda API or SDKs). Upload larger files with Amazon S3.

50 MB (when uploaded through the Lambda console)

250 MB The maximum size of the contents of a deployment package, including layers and custom runtimes. (unzipped)

Give this information, is my below understanding correct?

Let's say I have defined the below in a cloudformation/stack.yml to be deployed with SAM CLI

Lambda Function 1
Lambda Function 2

Lambda Layers 1 - x86
Lambda Layers 2 - arm64

I would understand that this means:

  • Each individual function should be smaller than 50 mb as a zip

  • Each individual layer should be smaller than 50mb as a zip

  • Lamba Function 1 + Lambda Layers 1 (unzipped) should be smaller than 250mb

  • Lambda Function 2 + Lambda Layers 2 (unzipped) should be smaller than 250mb

As I understand, if any of the above are false, I should fall back on S3, but what is the max size (zip and unzipped) if my layers are on S3?


Are all of the above correct?

I'm surfacing this concern because my current approach using SAM CLI allows me to deploy:

Lambda Function 1 + Lambda Layers 1 
AND 
Lambda Function 2 + Lambda Layers 1 # only one layer deployed

BUT DOES NOT WORK AS:

Lambda Function 1 + Lambda Layers 1 
AND 
Lambda Function 2 + Lambda Layers 2 # trying to deploy the same layer with different arch simultaneously

Error:

CREATE_FAILED                            AWS::Lambda::LayerVersion                LambdaLayer2<some_id>             Resource handler returned message:
                                                                                                                           "Unzipped size must be smaller than
                                                                                                                           262144000 bytes (Service: Lambda,
                                                                                                                           Status Code: 400, Request ID:
                                                                                                                           <some_id>)
                                                                                                                           (SDK Attempt Count: 1)" (RequestToken:
                                                                                                                           <some_token>,
                                                                                                                           HandlerErrorCode: InvalidRequest)
1 Answer
1

Your understanding is mostly correct, but there are a few clarifications and additional points to consider:

  1. You're correct that each individual function should be smaller than 50 MB as a zip file when uploaded through the Lambda console or API.

  2. For layers, the 50 MB limit applies when uploading directly through the Lambda console. However, when using the Lambda API or SDKs (which includes deployment through SAM CLI), you can upload layer zip files up to 250 MB.

  3. Your understanding of the combined size limit is correct. The total unzipped size of the function and all its layers must not exceed 250 MB. This applies to both Lambda Function 1 + Lambda Layers 1 and Lambda Function 2 + Lambda Layers 2.

  4. Regarding S3, it's a bit different than you've described. Using S3 doesn't change the maximum size limits. Instead, it allows you to upload larger zip files (up to 250 MB) that you couldn't upload directly through the console or API. The unzipped limit of 250 MB still applies regardless of whether you use S3 or not.

  5. You can add up to five layers to a Lambda function.

  6. It's important to note that these size limits refer to the deployment package size, not the total code size including dependencies that might be installed during runtime.

  7. If your deployment package exceeds these limits even when using S3, you might need to consider using container images for your Lambda functions, which support much larger deployments (up to 10 GB).

Remember, while staying within these limits, it's also important to keep your deployment packages as small as possible for optimal performance and faster cold starts.
Sources
Lambda quotas - AWS Lambda
Adding layers to functions - AWS Lambda
unable to upload zip folder from s3 to aws lambda | AWS re:Post

profile picture
answered 24 days ago
profile picture
EXPERT
reviewed 24 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions