Serverless
How to Check Lambda Logs in CloudWatch
Learn how to view Lambda execution logs in CloudWatch Logs and use them to investigate errors in a contact form API.
After building an API with Lambda, make sure you can review its logs in CloudWatch Logs. When you investigate issues with a contact form API, this is one of the first places to look.
Summary
Lambda execution logs are written to CloudWatch Logs. When an error happens, open the Lambda log group and use the requestId and error messages to find the cause.
What to Look for in CloudWatch Logs
For a contact form API, check the following points:
- Whether the Lambda function was invoked
- Whether validation errors occurred
- Whether DynamoDB
PutItemfailed - Whether CORS or JSON parsing failed
- Whether the function timed out
Log Groups
When Lambda runs, it usually writes logs to a log group named /aws/lambda/<function-name>. In this project, you would check the log group for contact-submit-prod.
Log streams are split by execution unit or time window. Find the most recent execution and read the error messages.
Logs You Should Emit
Logs that are safe and useful to emit include: successful processing, the field name that failed validation, DynamoDB save failures, requestId, and contactId.
For example, a log line such as INFO contact submitted contactId=contact-xxxx is helpful during investigation.
Logs You Must Not Emit
Do not log full email addresses, full message bodies, AWS credentials, API keys, or JWTs.
Logs are read by operators, but as retention grows, they also become a data leak risk. Design your logging so it never includes personal information.
Retention
If you set CloudWatch Logs to retain logs indefinitely, the volume keeps growing. For a personal MVP, set a short retention period to reduce both cost and information-management risk.
Incident Investigation Flow
- Check the error message in the frontend
- Check the API Gateway status code
- Read the Lambda CloudWatch Logs
- Confirm whether the record was saved in DynamoDB
- Check CORS, environment variables, and IAM permissions
Related Terms
What to Read Next
What to learn next
Combine blog posts with the AWS glossary, service comparisons, practice questions, and architecture gallery to connect exam knowledge with implementation.