Objective: Use Amazon CloudWatch to view and manage activity logs of Lambda functions (
DynamoDBBackup,getStudentData,insertStudentData) in the serverless system. Focus on checking logs of theinsertStudentDatafunction (integrated with the POST /students endpoint, section 4.5) to monitor student data saving to DynamoDBstudentDataand email sending via Amazon SES. Logs help verify functionality, detect errors, and optimize performance.
DynamoDBBackup, getStudentData, insertStudentData) in Log Groups for monitoring, debugging, and performance analysis.insertStudentData function (section 3.2) handles POST /students, saves records (studentid, name, class, birthdate, email) to DynamoDB studentData, and sends confirmation emails via SES.StudentWebsiteDistribution, sections 7.1–7.3) from S3 student-management-website-2025 (sections 6.1–6.4) calls the student API (stage prod, section 4.8) with Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod) and StudentApiKey (section 4.2).getStudentData.student-backup-20250706 (section 6.5) via DynamoDBBackup (section 8.1).https://d12345678.cloudfront.net).DynamoDBBackupRoleStudent (section 6.5) grants DynamoDB, S3, SES permissions.DailyDynamoDBBackup (section 8.2) runs backup at 07:00 AM +07.Access AWS Management Console and CloudWatch
us-east-1 to synchronize with DynamoDB studentData, S3 (student-management-website-2025, student-backup-20250706), Lambda, API Gateway, SES, CloudFront.
Figure 1: AWS Console interface with CloudWatch search bar.Select Log Groups
/aws/lambda/DynamoDBBackup (for POST /backup, section 8.1)./aws/lambda/getStudentData (for GET /students, section 4.4)./aws/lambda/insertStudentData (for POST /students, section 4.5).
Figure 2: Log Groups list.Select the Log Group for Lambda insertStudentData
/aws/lambda/insertStudentData.insertStudentData function, recording POST /students activity (saving records to studentData, sending SES email).curl -X POST https://abc123.execute-api.us-east-1.amazonaws.com/prod/students \
-H "x-api-key: xxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"studentid":"SV005","name":"Pham Thi E","class":"CNTT05","birthdate":"2001-05-05","email":"student5@example.com"}'
Figure 3: insertStudentData Log Group interface.View Log Streams
/aws/lambda/insertStudentData, view the list of Log Streams (e.g., 2025/07/09/[$LATEST]abc123).https://d12345678.cloudfront.net).
Figure 4: Log Streams list.Analyze Information in Log Stream
console.log (e.g., Successfully saved to DynamoDB).studentData, email sent via SES. Verify record (e.g., SV005) in DynamoDB and email at student5@example.com.dynamodb:PutItem, ses:SendEmail permissions in DynamoDBBackupRoleStudent.studentid).no-reply@studentapp.com or student5@example.com not verified in SES.
Figure 5: Log Stream details.Use CloudWatch Logs Insights
/aws/lambda/insertStudentData.fields @timestamp, @message
| filter @message like /Successfully saved to DynamoDB/
| sort @timestamp desc
| limit 20
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20
dynamodb:PutItem, ses:SendEmail permissions in DynamoDBBackupRoleStudent:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:PutItem",
"ses:SendEmail"
],
"Resource": [
"arn:aws:dynamodb:us-east-1:<AWS_ACCOUNT_ID>:table/studentData",
"arn:aws:ses:us-east-1:<AWS_ACCOUNT_ID>:identity/*"
]
}
]
}
<AWS_ACCOUNT_ID> with your AWS account ID.studentid, name not empty).
Figure 6: CloudWatch Logs Insights.| Factor | Details |
|---|---|
| Security | - Ensure the DynamoDBBackupRoleStudent role only grants necessary permissions (dynamodb:PutItem, ses:SendEmail). - Do not embed StudentApiKey in scripts.js. Use CloudFront Functions: javascript <br> function handler(event) { <br> var request = event.request; <br> request.headers['x-api-key'] = { value: 'xxxxxxxxxxxxxxxxxxxx' }; <br> return request; <br> } <br> |
| Optimization | - Enable CloudWatch Logs for Lambda (section 8.1). - Use AWS CLI to check logs: bash <br> aws logs describe-log-streams --log-group-name /aws/lambda/insertStudentData <br> |
| Integration | - Verify CORS in API Gateway (section 4.7): Access-Control-Allow-Origin: https://d12345678.cloudfront.net. - Test POST /students via CloudFront URL to generate new logs. |
| Integration Testing | - Access CloudFront URL (https://d12345678.cloudfront.net): - POST /students: Save record, send SES email. - GET /students: Display table. - POST /backup: Create file in student-backup-20250706, send email. - Use Developer Tools > Network to inspect API requests. |
| Error Handling | - No logs: Check CloudWatch Logs are enabled in Lambda, trigger the function via API. - AccessDenied: Verify logs:DescribeLogGroups, logs:GetLogEvents permissions. - ValidationException: Check input data. - SES error: Verify SES email. |
Best practice tip: Trigger POST /students via the web interface to generate new logs. Use Logs Insights to quickly filter errors. Set CloudWatch Alarms for Duration or Memory Used if you need performance monitoring.
CloudWatch Logs allow you to monitor the activity of the insertStudentData Lambda, verify data is saved to studentData and emails are sent via SES. Logs help debug and optimize the serverless system, integrated with the student API and web interface via CloudFront.
Next step: Optimize the system or set up CloudWatch Alarms for