Skill 4.3.2
Optimize memory and compute power for an application.
Key Concepts
For Lambda, compare max memory used with the configured size, and run AWS Lambda Power Tuning, which invokes the function at several memory sizes and charts cost against speed. Because CPU scales with memory, the cheapest setting is not always the smallest.
For EC2 and ECS, compare CPU and memory utilisation in CloudWatch (memory needs the CloudWatch agent or Container Insights) with the allocated size. Load testing before release confirms the chosen size handles peak traffic.
Because CPU scales with memory, increasing memory often makes a function faster and can lower total cost. The open-source AWS Lambda Power Tuning tool runs a function at different memory sizes to find the best balance, and the maximum memory used in each REPORT log line shows how much headroom remains.
To reduce latency, initialise SDK clients and connections outside the handler so warm invocations reuse them, keep deployment packages small, and load only the dependencies you need. Provisioned concurrency or SnapStart remove most cold-start delay. Choosing the Arm-based Graviton architecture often gives better price-performance.