Skill 4.3.5
Detect performance bottlenecks by using AWS services (for example, Amazon CloudWatch).
Key Concepts
Start with metrics to find when and where latency or errors increased, then use X-Ray traces and the service map to see which component is slow. Common causes include Lambda cold starts or too little memory, throttling (Lambda concurrency, DynamoDB capacity, API Gateway limits), hot DynamoDB partitions, database connection exhaustion, slow third-party calls and missing caches.
Once found, confirm the cause, apply a targeted fix such as more memory, provisioned concurrency, an index, caching or RDS Proxy, and verify the improvement with the same metrics. CloudWatch Application Signals and Contributor Insights speed up this analysis.
Lambda's REPORT lines provide duration, init duration and memory used for every invocation, and CloudWatch Logs Insights can aggregate them, for example stats avg(@duration), max(@duration), pct(@duration, 99) by bin(5m) to spot slow periods, or filter for @initDuration to measure cold starts.
Applications can log their own timings for key steps, such as database queries and external calls, in structured JSON so Logs Insights can aggregate them by operation. API Gateway access logs record latency per request, and ELB access logs show request processing times for each target.
X-Ray traces and custom subsegments show the time spent in each downstream call and in named sections of code, and CloudWatch Lambda Insights shows CPU, memory and network usage per function. CloudWatch Application Signals adds latency percentiles per operation, which identify the slowest operations worth optimising.
Lambda's REPORT log line records duration, billed duration, memory size, maximum memory used and init duration for every invocation, which together reveal cold starts and over- or under-provisioned memory.
Reuse connections and SDK clients, batch requests (SendMessageBatch, BatchWriteItem, PutRecords), and use long polling for SQS. Choose efficient compute such as Arm-based Graviton for Lambda and containers, right-size memory and instances, and use Auto Scaling so capacity follows demand.
For data, use queries instead of scans, project only needed attributes, pick on-demand or provisioned capacity to match traffic, compress payloads and move cold data to cheaper storage classes. Event filtering ensures functions only run for relevant events.