Applying a Method for Debugging on AWS
This lesson sets out a consistent method for finding and fixing problems, the subject of Domain 4 of the exam. Most AWS errors fall into a small number of categories, and the method finds the cause quickly: read the error exactly, decide which category it belongs to, and use the tool that shows that category best.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the five categories of error and the signs of each.
- Choose the diagnostic tool that answers each kind of question.
- Extract the principal, action and resource from an AWS error message.
Five categories of error
When something fails on AWS, the error usually belongs to one of five categories, and identifying the category first tells the developer where to look. Permissions errors say so explicitly: the response contains AccessDenied, UnauthorizedOperation or HTTP 403, and AWS CloudTrail records the denied call. Networking problems are recognisable by the absence of a clear error: a call simply times out, or the connection is refused, because a security group, route or VPC endpoint is missing.
Limits and throttling produce HTTP 429 or exceptions such as ThrottlingException and ProvisionedThroughputExceededException, often only under load, and CloudWatch metrics show when the limit was reached. Configuration errors appear as "resource not found", validation errors or wrong behaviour, for example code calling a resource in the wrong Region or a function invoked through the wrong alias. Code errors appear as exceptions and stack traces in the application's logs, or as wrong results. The following table summarises the signs of each category and where to look.
| Category | Typical signs | Where to look |
|---|---|---|
| Permissions | AccessDenied, AccessDeniedException, UnauthorizedOperation, 403 | CloudTrail error events, IAM policy simulator, decoded authorisation messages |
| Networking | Timeouts with no error message, connection refused | Security groups, route tables, VPC endpoints, VPC Flow Logs, Reachability Analyzer |
| Limits and throttling | 429, ThrottlingException, ProvisionedThroughputExceededException, TooManyRequestsException | CloudWatch throttle and usage metrics, the account quota values |
| Configuration | Resource not found, validation errors, wrong behaviour | Environment variables, stage or alias, Region, event source settings |
| Code | Exceptions and stack traces in logs, wrong results | CloudWatch Logs, X-Ray traces, local reproduction with SAM |
The tools
Each diagnostic tool answers a different question, so using the right one saves time. CloudWatch metrics show when a problem started and how widespread it is, for example whether errors affect every request or only some. CloudWatch Logs, searched with Logs Insights, show what the code did. AWS X-Ray shows where in a chain of services a request becomes slow or fails. AWS CloudTrail shows who called which API and whether the call was denied.
Two AWS STS commands help with identity problems. aws sts get-caller-identity shows which identity is actually being used, which is often not the one the developer expected. aws sts decode-authorization-message decodes the encoded failure message that some services, such as Amazon EC2, return with an authorisation error, revealing which policy denied the request. Finally, the SAM CLI can invoke a function locally with the same event that failed, so a code problem can be reproduced and fixed with a debugger. The following table summarises the tools.
| Tool | Shows |
|---|---|
| CloudWatch Logs and Logs Insights | What the code did and what it logged |
| CloudWatch metrics | When the problem started and how widespread it is |
| AWS X-Ray | Which service in a chain is slow or failing |
| AWS CloudTrail | Which API calls were made or denied, by whom |
aws sts get-caller-identity | Which identity the code is actually using |
aws sts decode-authorization-message | Why an encoded EC2-style authorisation failure happened |
| SAM CLI local invoke | Reproducing the problem with the same event |
Read the error before acting
AWS error messages are often specific. "User: arn:aws:sts::111122223333:assumed-role/orders-fn/orders-fn is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:eu-west-1:111122223333:table/Orders because no identity-based policy allows the dynamodb:PutItem action" names the identity, the action, the resource and the reason. Reading it fully usually makes the fix obvious; guessing usually adds broad permissions that create a security problem.
Following the method
A function that writes to S3 starts failing after a deployment. The developer follows the method:
-
Read the error
AccessDeniedonPutObject. -
Category
Permissions.
-
Identity
CloudTrail shows the call came from the role
orders-fn-v2, a new role created by the deployment. -
Cause
The new role's policy grants
s3:PutObjectonarn:aws:s3:::orders-archive(the bucket), notarn:aws:s3:::orders-archive/*(its objects). -
Fix
Correct the resource ARN, confirm with the IAM policy simulator, and redeploy.
A function in a VPC times out while calling an external API, with no error message. Which category of problem is most likely?
Show answer
Networking. A timeout without an error usually means the request never got an answer, for example because the subnet has no route to a NAT gateway.
Exam Tips
Remember for the exam
- Classify the error: permissions, networking, limits, configuration or code.
- Read AccessDenied messages fully; they name the identity, action, resource and reason.
- Timeouts without errors usually mean a networking problem.
- Use CloudTrail to see denied calls and X-Ray to find slow dependencies.
- Check which identity is in use with sts get-caller-identity.