Configure Lambda function memory
Lambda allocates CPU power in proportion to the amount of memory configured. Memory is the amount of memory available to your Lambda function at runtime. You can increase or decrease the memory and CPU power allocated to your function using the Memory setting. You can configure memory between 128 MB and 10,240 MB in 1-MB increments. At 1,769 MB, a function has the equivalent of one vCPU (one vCPU-second of credits per second).
This page describes how and when to update the memory setting for a Lambda function.
Sections
Determining the appropriate memory setting for a Lambda function
Memory is the principal lever for controlling the performance of a function. The default setting, 128 MB, is the lowest possible setting. We recommend that you only use 128 MB for simple Lambda functions, such as those that transform and route events to other AWS services. A higher memory allocation can improve performance for functions that use imported libraries, Lambda layers, Amazon Simple Storage Service (Amazon S3) or Amazon Elastic File System (Amazon EFS). Adding more memory proportionally increases the amount of CPU, increasing the overall computational power available. If a function is CPU, network or memory-bound, then increasing the memory setting can dramatically improve its performance.
To find the right memory configuration, monitor your functions with Amazon CloudWatch and set alarms if memory consumption is approaching the configured maximums. This can help identify memory-bound functions. For CPU-bound and IO-bound functions, monitoring the duration can also provide insight. In these cases, increasing the memory can help resolve the compute or network bottlenecks.
You can also consider using the open source
AWS Lambda Power Tuning
Configuring function memory (console)
You can configure the memory of your function in the Lambda console.
To update the memory of a function
Open the Functions page
of the Lambda console. -
Choose a function.
-
Choose the Configuration tab and then choose General configuration.
-
Under General configuration, choose Edit.
-
For Memory, set a value from 128 MB to 10,240 MB.
-
Choose Save.
Configuring function memory (AWS CLI)
You can use the update-function-configuration
aws lambda update-function-configuration \ --function-name
my-function
\ --memory-size1024
Configuring function memory (AWS SAM)
You can use the AWS Serverless Application Model to configure memory for your function. Update the MemorySize property in your template.yaml
file and then run sam deploy.
Example template.yaml
AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: An AWS Serverless Application Model template describing your function. Resources:
my-function
: Type: AWS::Serverless::Function Properties: CodeUri: . Description: '' MemorySize:1024
# Other function properties...
Accepting function memory recommendations (console)
If you have administrator permissions in AWS Identity and Access Management (IAM), you can opt in to receive Lambda function memory setting recommendations from AWS Compute Optimizer. For instructions on opting in to memory recommendations for your account or organization, see Opting in your account in the AWS Compute Optimizer User Guide.
Note
Compute Optimizer supports only functions that use x86_64 architecture.
When you've opted in and your Lambda function meets Compute Optimizer requirements, you can view and accept function memory recommendations from Compute Optimizer in the Lambda console in General configuration.