By using AWS re:Post, you agree to the Terms of Use

Force my AWS Lambda function to use X memory

0

I want to force my lambda function to alway use at least 6000 MB of memory when its invoked, for the whole timeout, until it has finished.

I have a lambda function that i have given a memorySize of 9216 MB, and because i'm running a high computational task, it has to use most of this memory for it to be able to finish before the timeout i set (90 seconds), sometimes it uses around the amount of memory i assigned, which is around 5500 MB to 4500 MB and works ok, but randomly and consistently, my lambda will only use 1000 or 500 MB, even though i set the memorySize of my lambda to 9216 MB. So i want to force my lambda to use at least 6000 MB of memory every time its invoked, so i don't keep running into this error.

Screeshot of error: https://i.stack.imgur.com/3LWhE.png

2 Answers
1

Time taken for Lambda execution will have multiple factors like memory, cpu, network involved. The screenshot shared indicates that the operation you are performing is not memory intensive as it is consuming only small portion of total memory allocated. When a Lambda function is invoked, the function will be allocated with the maximum memory configured and equivalent vCPUs allocated i.e. every 1769MB of memory allocated will have 1vCPU allocated.

You can increase the memory to maximum allowed value of 10240MB and test if it improves the performance with little more additional vCPU added. Also, suggest you to look at optimizing the function by identifying the code snippet taking time. If it has any network calls involved or extensive computations involved, it may be ideal to increase the timeout value.

https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html?icmpid=docs_console_unmapped#configuration-memory-console

You can also, create functions with both x86_64 and ARM processors to compare the performance and choose the best one for your function.

You can also opt-in for the Compute Optimizer recommendations (only supports x86_64 based functions at this time) - https://docs.aws.amazon.com/compute-optimizer/latest/ug/getting-started.html?icmpid=docs_lambda_help#account-opt-in https://docs.aws.amazon.com/compute-optimizer/latest/ug/requirements.html?icmpid=docs_lambda_help#requirements-lambda-functions

Also, can profile the functions - https://docs.aws.amazon.com/lambda/latest/operatorguide/profile-functions.html

profile picture
answered a month ago
0

The Lambda services doesn't determine nor control the amount of memory that your function uses - that's up to the code that you write; the libraries you use and the runtime that you're running the code in.

If you're having issues where the code is behaving inconsistently (and in this case timing out because there's something going wrong) I'd suggest debugging all of the things above to find out where the issue is. But Lambda itself will not "force" your code to use any resources that you give it; it's up to the code to do that.

EXPERT
answered a month 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