Objective: Update the configuration for the Lambda function
BackupDynamoDBAndSendEmail(created in section 3.3, integrated with the POST /backup endpoint, section 4.6) to ensure efficient operation when backing up data from the DynamoDB tablestudentDatato the S3 Bucketstudent-backup-20250706(section 6.5) and sending notification emails via Amazon SES. The configuration includes Memory, Ephemeral Storage, Execution Role, and Environment Variables to optimize performance and integrate with the serverless system.
BackupDynamoDBAndSendEmail:
student API (stage prod, section 4.8), reads data from DynamoDB studentData, saves a JSON file to S3 student-backup-20250706, and sends a notification email via SES.StudentWebsiteDistribution, sections 7.1–7.3) from S3 Bucket student-management-website-2025 (sections 6.1–6.4) calls the student API with Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod) and StudentApiKey (section 4.2).studentData and send email via SES.student-backup-20250706 and send a notification email.https://d12345678.cloudfront.net).DynamoDBBackupRole (section 6.5) grants access to DynamoDB, S3, and SES.You need to complete the following:
student-backup-20250706.BackupDynamoDBAndSendEmail with role DynamoDBBackupRole.student API, including StudentApiKey, StudentUsagePlan, GET /students, POST /students, POST /backup methods, enable CORS, and deploy the prod stage.index.html, styles.css, scripts.js.student-management-website-2025 and student-backup-20250706.StudentWebsiteDistribution.lambda:UpdateFunctionConfiguration, lambda:GetFunction, s3:PutObject, dynamodb:Scan, ses:SendEmail, and the AWS region is us-east-1.Access AWS Management Console and Lambda
us-east-1 to synchronize with DynamoDB studentData, S3 (student-management-website-2025, student-backup-20250706), API Gateway, SES, and CloudFront.
Figure 1: AWS Console interface with Lambda search bar.Select Functions List
BackupDynamoDBAndSendEmail (section 3.3) appears.lambda:GetFunction permission:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:GetFunction",
"Resource": "arn:aws:lambda:us-east-1:<AWS_ACCOUNT_ID>:function:BackupDynamoDBAndSendEmail"
}
]
}
<AWS_ACCOUNT_ID> with your AWS account ID.
Figure 2: Lambda Functions list.Select the Backup Lambda Function
BackupDynamoDBAndSendEmail to enter the details page.DynamoDBBackupRole (section 6.5).
Figure 3: Lambda function details interface.Access the Configuration Tab
Update General Configuration
DynamoDBBackupRole.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:Scan",
"s3:PutObject",
"ses:SendEmail"
],
"Resource": [
"arn:aws:dynamodb:us-east-1:<AWS_ACCOUNT_ID>:table/studentData",
"arn:aws:s3:::student-backup-20250706/*",
"arn:aws:ses:us-east-1:<AWS_ACCOUNT_ID>:identity/*"
]
}
]
}
<AWS_ACCOUNT_ID> with your AWS account ID.DynamoDBBackupRole (section 6.5) and iam:PassRole permission.studentData, student-backup-20250706, and SES identity are correct.
Figure 4: Update General configuration.Save Configuration
DynamoDBBackupRole) are updated.lambda:UpdateFunctionConfiguration permission:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:UpdateFunctionConfiguration",
"Resource": "arn:aws:lambda:us-east-1:<AWS_ACCOUNT_ID>:function:BackupDynamoDBAndSendEmail"
}
]
}
DynamoDBBackupRole.
Figure 5: Save configuration success notification.Create Environment Variables
S3_BUCKET_NAME, Value: student-backup-20250706 (target bucket for backup JSON).SENDER_EMAIL, Value: no-reply@studentapp.com (SES verified email).RECIPIENT_EMAIL, Value: admin@studentapp.com (SES verified email).lambda:UpdateFunctionConfiguration permission.student-backup-20250706 (section 2.4).no-reply@studentapp.com and admin@studentapp.com in SES (section 3).
Figure 6: Add Environment variables.Test Lambda Configuration
{} (simulate EventBridge).students-backup-20250708T1236.json) appears in S3 student-backup-20250706.admin@studentapp.com with subject Backup Completed: students-backup-20250708T1236.json and body Backup saved to s3://student-backup-20250706/students-backup-20250708T1236.json.s3:PutObject, dynamodb:Scan, ses:SendEmail permissions in DynamoDBBackupRole.studentData.no-reply@studentapp.com, admin@studentapp.com in SES (section 3).S3_BUCKET_NAME, SENDER_EMAIL, RECIPIENT_EMAIL in Environment variables.
Figure 7: Lambda test result.| Factor | Details |
|---|---|
| Security | - Avoid embedding StudentApiKey in scripts.js. Use CloudFront Functions to add the x-api-key header: javascript <br> function handler(event) { <br> var request = event.request; <br> request.headers['x-api-key'] = { value: 'xxxxxxxxxxxxxxxxxxxx' }; <br> return request; <br> } <br> - Verify SES emails (no-reply@studentapp.com, admin@studentapp.com) before sending. |
| Optimization | - Enable CloudWatch Logs for Lambda: In Configuration > Monitoring and operations tools, select Enable CloudWatch Logs. - Use AWS CLI to check configuration: bash <br> aws lambda get-function-configuration --function-name BackupDynamoDBAndSendEmail <br> |
| Integration | - CORS: Ensure Access-Control-Allow-Origin: https://d12345678.cloudfront.net in API Gateway (section 4.7). - Verify POST /students, GET /students, POST /backup endpoints work with StudentApiKey. |
| Integration Testing | - Access CloudFront URL (https://d12345678.cloudfront.net) and check: - 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 | - AccessDenied: Check permissions in DynamoDBBackupRole and bucket policy of student-backup-20250706. - SES error: Verify SES emails. - No data: Add data to studentData via POST /students. - Environment variable error: Check environment variables in Configuration. |
Best practice tip: Test Lambda after each update using the
{}event. Check CloudWatch Logs for debugging. Prepare for section 8.2 by ensuring the function works correctly with the POST /backup endpoint.
The Lambda function BackupDynamoDBAndSendEmail has been configured with Memory (128 MB), Ephemeral Storage (512 MB), role DynamoDBBackupRole, and environment variables (S3_BUCKET_NAME, SENDER_EMAIL, RECIPIENT_EMAIL). The function is ready to back up data from DynamoDB studentData to S3 student-backup-20250706 and send emails via SES, integrated with the student API and web interface.
Next step: Proceed to Create EventBridge Rule for Automated Backup to enable scheduled backups!