Objective: Create the S3 Bucket
student-backup-20250706(if not already created in section 2.4) and configure the Bucket Policy to allow the Lambda functionBackupDynamoDBAndSendEmail(with theDynamoDBBackupRolerole, section 3.3) to write backup files (JSON/CSV) to the bucket via the POST /backup endpoint (section 4.6). This bucket stores backup data from the DynamoDB tablestudentDataand integrates with SES to send notification emails. The bucket does not require public access, onlys3:PutObjectpermission for theDynamoDBBackupRolerole, ensuring security and seamless integration with the serverless system.
student-backup-20250706 bucket:
BackupDynamoDBAndSendEmail when calling the POST /backup endpoint.DynamoDBBackupRole role to write files (s3:PutObject, s3:PutObjectAcl), with no public access.student API (stage prod, section 4.8) and SES to send notification emails after backup.BackupDynamoDBAndSendEmail (section 3.3):
studentData (dynamodb:Scan, dynamodb:Query).student-backup-20250706 (s3:PutObject).ses:SendEmail, ses:SendRawEmail).scripts.js, section 6.2) via the Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod/backup) with header x-api-key: <StudentApiKey> (section 4.2).student-backup-20250706 bucket only needs write access from Lambda, not public access like the student-management-website-2025 bucket (section 6.4).DynamoDBBackupRole role to access.You need to complete section 2.4 (create the student-backup-20250706 bucket), section 3.3 (create the Lambda function BackupDynamoDBAndSendEmail with the DynamoDBBackupRole role), section 4.1 (create the student API), section 4.2 (create the StudentApiKey), section 4.3 (create the StudentUsagePlan), section 4.6 (create the /backup resource and POST /backup method), section 4.7 (enable CORS), section 4.8 (deploy the API to the prod stage), section 4.9 (attach StudentApiKey to StudentUsagePlan), section 5 (build the web interface with scripts.js), section 6.1 (create the student-management-website-2025 bucket). Ensure your AWS account has s3:CreateBucket, s3:PutBucketPolicy permissions and the AWS region is us-east-1.
Access AWS Management Console
student-backup-20250706 bucket, student API, Lambda functions (getStudentData, insertStudentData, BackupDynamoDBAndSendEmail), DynamoDB table studentData, and SES. The region is shown in the top right corner of the AWS Console.
Create the student-backup-20250706 Bucket
student-backup-20250706 bucket (assumed created in section 2.4). If it exists, skip creation and move to Step 3.
student-backup-20250706.
student-backup-20250706-abc123).
aws s3api put-bucket-versioning --bucket student-backup-20250706 --versioning-configuration Status=Enabled

Project=StudentManagement, Environment=Production.

student-backup-20250706-<random-string>). Check s3:CreateBucket permission in your IAM role.s3:CreateBucket permission:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:CreateBucket",
"Resource": "*"
}
]
}
Access the Bucket’s Permissions Tab
student-backup-20250706 bucket.
Edit the Bucket Policy
DynamoDBBackupRole role to write files (s3:PutObject, s3:PutObjectAcl):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowLambdaPutObject",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/DynamoDBBackupRole"
},
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::student-backup-20250706/*"
}
]
}
BackupDynamoDBAndSendEmail.s3:PutObject: Allows writing backup files to the bucket.s3:PutObjectAcl: Allows setting ACL on files (if needed).student-backup-20250706 bucket.<AWS_ACCOUNT_ID>:
arn:aws:iam::123456789012:role/DynamoDBBackupRole.
Save Changes

arn:aws:s3:::student-backup-20250706/*).DynamoDBBackupRole is correct and the role exists in IAM.s3:PutBucketPolicy permission:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:PutBucketPolicy",
"Resource": "arn:aws:s3:::student-backup-20250706"
}
]
}
Check Lambda Permissions
DynamoDBBackupRole role:
DynamoDBBackupRole (created in section 3.3).s3:PutObject and s3:PutObjectAcl permissions for the student-backup-20250706 bucket:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::student-backup-20250706/*"
}
]
}
curl -X POST https://abc123.execute-api.us-east-1.amazonaws.com/prod/backup \
-H "x-api-key: xxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json"
backup-20250706.json).DynamoDBBackupRole has s3:PutObject permission and is attached to the BackupDynamoDBAndSendEmail Lambda./aws/lambda/BackupDynamoDBAndSendEmail) for errors.Access-Control-Allow-Origin header in Lambda (section 3.3) and API Gateway (section 4.7).| Factor | Details |
|---|---|
| Security | Keep Block all public access enabled to ensure the student-backup-20250706 bucket is not publicly accessible. Only the DynamoDBBackupRole role is allowed to write files. Avoid embedding StudentApiKey in scripts.js; use AWS Secrets Manager or CloudFront Functions: function handler(event) { var request = event.request; request.headers[‘x-api-key’] = { value: ‘xxxxxxxxxxxxxxxxxxxx’ }; return request; } |
| Optimization | Enable S3 Access Logs: In S3 > student-backup-20250706 > Properties > Server access logging, select Enable, specify a log bucket (e.g., student-backup-logs-20250706). Use AWS CLI to automate: aws s3api put-bucket-policy –bucket student-backup-20250706 –policy file://policy.json |
| System integration | Ensure the POST /backup endpoint works with the Invoke URL and StudentApiKey. Update CORS in API Gateway (section 4.7) with Access-Control-Allow-Origin: https://d12345678.cloudfront.net. Integrate with CloudFront (section 7) to call the API from the web interface. |
| Integration testing | Call POST /backup from the web interface (https://d12345678.cloudfront.net) or curl. Check: - Backup file appears in student-backup-20250706. - SES email is sent. Use Developer Tools > Network to inspect API requests. |
| Troubleshooting | 403 Forbidden: Check ARN in Bucket Policy, s3:PutObject permission for DynamoDBBackupRole. File not appearing: Check CloudWatch logs, Lambda code. CORS: Check Access-Control-Allow-Origin header in Lambda (section 3.3) and API Gateway (section 4.7). 429: Check Rate/Burst/Quota limits in StudentUsagePlan (section 4.3). |
Practical tip: Check the Bucket Policy and IAM permissions of
DynamoDBBackupRolebefore calling POST /backup. Use AWS CLI to automate if you need to apply the policy to multiple buckets. Prepare for section 7 (CloudFront configuration) to complete the integration.
The student-backup-20250706 bucket has been created and the Bucket Policy configured to allow the BackupDynamoDBAndSendEmail Lambda function to write backup files. The bucket is ready to integrate with the POST /backup endpoint and CloudFront (section 7).
Next step: Go to Configure CloudFront for content distribution to continue setup!