Lesson 2 of 2 Troubleshooting and Debugging Playbook

Recognising Common Errors and Their Causes

This lesson gathers the symptoms developers meet most often, service by service, with their most likely causes. Many exam questions describe exactly one of these symptoms.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the likely causes of common Lambda and API Gateway errors.
  • Explain how design limits of data and messaging services appear as errors.
  • Find the root cause of a failed CloudFormation, CodeDeploy or CodeBuild deployment.

AWS Lambda

Lambda errors usually come from the function's configuration rather than its code. A function stops at its timeout, which defaults to only three seconds, so a slow dependency, or a function in a VPC that cannot reach a service because it has no NAT gateway or VPC endpoint, appears as a timeout. Throttling with HTTP 429 means the account's concurrency or the function's reserved concurrency is exhausted. A function that works on a developer's machine but is denied access in Lambda runs with its execution role, not the developer's credentials, and the role lacks a permission. The following table lists the most common symptoms and causes.

SymptomMost likely cause
Task timed out after 3.00 secondsDefault timeout too low; slow dependency; missing VPC endpoint or NAT
429 TooManyRequestsExceptionAccount or reserved concurrency reached
Runtime.ImportModuleErrorDependency not packaged, or handler name wrong
Out of memory (Runtime exited with error: signal: killed)Memory setting too low
Works locally, AccessDenied in LambdaExecution role lacks permissions that the developer's own credentials have
Asynchronous events lostNo on-failure destination or DLQ
Stream processing stuck, IteratorAge risingA poison record retried forever; set retry limits and bisect on error

API Gateway

API Gateway status codes indicate which side of the gateway failed. A 502 Bad Gateway means the integration answered, but not in the form API Gateway expected, which with a Lambda proxy integration usually means the function returned something other than an object with statusCode, headers and a string body. A 504 Gateway Timeout means the integration did not answer within the integration timeout. A 403 "Missing Authentication Token" is misleading: it usually means the path or method does not exist, often because changes to a REST API were never deployed to the stage. The following table lists these and other common symptoms.

SymptomMost likely cause
502 Bad GatewayMalformed Lambda proxy response
504 Gateway TimeoutIntegration exceeded the timeout
403 Missing Authentication TokenWrong path or method, or changes not deployed
CORS error in the browser onlyMissing OPTIONS method or CORS headers, including on error responses
401 UnauthorizedMissing or expired token; wrong authorizer configuration

Data and messaging

Errors in data and messaging services often reflect the service's design limits. DynamoDB divides a table into partitions by partition key, so throttling concentrated on one key means too much traffic goes to one partition. Batch operations can succeed partially, returning the items they could not process, which the application must retry. SQS makes a received message invisible for the visibility timeout; if processing takes longer, the message reappears and is processed twice. Encrypted S3 objects need permission on the KMS key as well as on the bucket, which is why only some objects in a bucket may be denied. The following table lists the most common symptoms.

SymptomMost likely cause
DynamoDB throttling on one keyHot partition from a low-cardinality partition key
DynamoDB items missing after BatchWriteItemUnprocessedItems not retried
DynamoDB base table throttledUnder-provisioned GSI
SQS messages processed twiceVisibility timeout shorter than processing time; no idempotency
SQS message never succeeds and reappears foreverNo dead-letter queue
Kinesis ProvisionedThroughputExceededToo few shards or uneven partition keys
S3 AccessDenied on some objects onlySSE-KMS objects need kms:Decrypt

Deployment

Deployment failures are diagnosed from the deployment tool's own records. A CloudFormation stack that rolls back lists many failed events, but only the first failure is the cause; the later ones are consequences of the rollback. CodeDeploy failures on every instance point to something common to all of them, such as the agent or the instance profile, rather than to one server. A build that passes despite failing tests has lost the test command's exit code, often because its output was piped into another command. The following table lists the most common symptoms.

SymptomMost likely cause
CloudFormation stack stuck or rolled backRead the first failed event; often permissions or a resource name conflict
CodeDeploy fails on every EC2 instanceAgent not running or instance profile cannot read the artifact
CodeBuild passes despite failing testsTest command's exit code swallowed by a pipe
ECS task stops with CannotPullContainerErrorTask execution role or network path to ECR
cdk deploy fails in a new accountAccount and Region not bootstrapped
Worked example

A slow API with no errors

An API's p99 latency jumps from 200 ms to 3 seconds, with no errors. The developer uses the signals in order:

1. CloudWatch metrics: Lambda Duration rose at 11:05; ConcurrentExecutions normal; no Throttles
2. X-Ray trace map:    95% of time is in calls to DynamoDB
3. DynamoDB metrics:   ThrottledRequests on a GSI; SuccessfulRequestLatency up
4. Cause:              a new query pattern uses the GSI, whose provisioned capacity was never raised
5. Fix:                raise the GSI's capacity (or switch the table to on-demand)

SDK retries were hiding the throttling as latency rather than errors, which is why no errors appeared. Following the chain from the symptom (latency) to the slow dependency (DynamoDB) to its own metrics found the cause in minutes.

Check yourself

API Gateway returns 504 after about 29 seconds while the Lambda function keeps running. What does this mean?

Show answer

The integration timed out because the backend took longer than API Gateway's integration timeout. Raising the function's own timeout does not help; the work must become faster or asynchronous.

Exam Tips

Remember for the exam

  • Lambda timeouts in a VPC often mean a missing VPC endpoint or NAT gateway.
  • API Gateway 502 with Lambda proxy usually means a malformed response.
  • Duplicate SQS processing points to the visibility timeout and missing idempotency.
  • S3 AccessDenied on only some objects often means missing KMS permissions.
  • Latency without errors can be SDK retries hiding throttling.