Lambda内存的配置是开发者调整Lambda性能的最主要手段，大小在128 MB 到 10,240 MB之间。
执行时间 x 分配的内存收费，增加内存会影响Lambda的帐单，有可能增加帐单，也有可能减少帐单例如下面的案例，在128MB或1024MB时，产生的费用较小：
Choosing the memory allocated to Lambda functions is an optimization process that balances speed (duration) and cost. While you can manually run tests on functions by selecting different memory allocations and measuring the time taken to complete, the AWS Lambda Power Tuning tool allows you to automate the process.
This tool uses AWS Step Functions to run multiple concurrent versions of a Lambda function at different memory allocations and measure the performance. The input function is run in your AWS account, performing live HTTP calls and SDK interaction, to measure likely performance in a live production scenario. You can also implement a CI/CD process to use this tool to automatically measure the performance of new functions you deploy.
You can graph the results to visualize the performance and cost trade-off. In this example, you can see that a function has the lowest cost at 1024 MB and 1536 MB of memory, but the fastest execution at 3008 MB:
Generally, CPU-bound Lambda functions see the most benefit when memory increases, whereas network-bound see the least. This is because more memory provides greater computational capability, but it does not impact the response time of downstream services in network calls. Running the profiler on your functions provides insight into how your code performs at different memory allocations, allowing you to make better decisions about how to configure your functions.
You can also use AWS Cost Optimizer to automate a cost-performance analysis for all the Lambda functions in an AWS account. This service evaluates functions that have run at least 50 times over the previous 14 days, and provides automatic recommendations for memory allocation. You can opt-in from the Cost Optimizer console to use this free recommendation engine.
As discussed in Monitoring and observability , you can monitor functions with CloudWatch and set alarms if memory consumption is approaching the configured maximum. This can help identify memory-bound functions. For CPU-bound and IO-bound functions, monitoring the duration can often provide more insight. In these cases, increasing the memory can help resolve the compute or network bottlenecks.
By default, Lambda allocates 512 MB for a function’s /tmp directory. You can increase or decrease this amount using the Ephemeral storage (MB) setting. To configure the size of a function’s /tmp directory, set a whole number value between 512 MB and 10,240 MB.
Configuring ephemeral storage past the default 512 MB allocated incurs a cost. For more information, see Lambda pricing .
You can configure the size of a function’s /tmp directory in the Lambda console.
To update the size of a function’s /tmp directory
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.
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.
To accept a function memory recommendation