Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda ENI limitation in VPC clarification

I found this in the AWS official docs for lambda:

If your Lambda function accesses a VPC, you must make sure that your VPC has sufficient ENI capacity to support the scale requirements of your Lambda function. You can use the following formula to approximately determine the ENI requirements.

Projected peak concurrent executions * (Memory in GB / 3GB)

I understand the reason behind this formula. My only question is: why 3GB? From where this number comes from?

like image 797
Vladyslav Usenko Avatar asked Dec 02 '25 14:12

Vladyslav Usenko


2 Answers

The formula Projected peak concurrent executions × (Memory in GB / 3GB) is a proxy for the answer to the actual (but unspoken) question "How many m-class (general purpose) EC2 instances will Lambda need to allocate in order to accommodate the required number of containers of this size?"

AWS Lambda allocates CPU power proportional to the memory by using the same ratio as a general purpose Amazon EC2 instance type, such as an M3 type.

https://docs.aws.amazon.com/lambda/latest/dg/resource-model.html

The ratio is "the same" because the M3... or something very similar to it... is what Lambda is actually using, under the hood, to host your containers.

The m3.medium is the smallest machine of the m3 family and has 3.75GB of RAM... so the number of this type of EC2 VM that lambda will need to provision -- and thus the number of ENIs that will be needed -- is approximately n × (m / 3GB). This instance could host (e.g.) approximately 2 × 1.5 GB or 24 × 128 MB or 1 × 3.0 GB containers, leaving some room for operational/management overhead within the VM.

How much overhead may be involved, and the algorithm Lambda uses when placing and selecting containers, and whether Lambda uses a mix of instance sizes and under what rules... are all part of the Lambda black box. Logic would dictate that Lambda would start with smaller instances and progress to larger ones as concurrency grows, since the larger instances (within the same family) would allow more packing efficiency without a performance penalty (since memory and CPU are dedicated, in a fixed ratio, to each container), particularly for large and oddly-sized containers. What this formula reveals that it is not containers that receive ENIs but rather instances... and there will be approximately n × (m / 3GB) instances allocated by Lambda under concurrency n of size m GB.

like image 189
Michael - sqlbot Avatar answered Dec 05 '25 07:12

Michael - sqlbot


3GB is the max memory allocation for a single lambda function. https://docs.aws.amazon.com/lambda/latest/dg/limits.html

like image 21
Pubudu Jayawardana Avatar answered Dec 05 '25 05:12

Pubudu Jayawardana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!