Objective: Configure the Bucket Policy for the S3 Bucket
student-management-website-2025
to allow public access (s3:GetObject
) to the static files (index.html
,styles.css
,scripts.js
from section 6.2). This ensures the static web interface (enabled with Static Website Hosting in section 6.3) can be accessed via the S3 endpoint or CloudFront (section 7). The Bucket Policy allows everyone (Principal: *
) to read the files, supporting integration with thestudent
API (stageprod
, section 4.8) to call the GET /students, POST /students, and POST /backup endpoints with API Key security (StudentApiKey
, section 4.2) and CORS (section 4.7).
s3:GetObject
) for browsers or CloudFront to read the static files (index.html
, styles.css
, scripts.js
).student
API (section 4.8) using the Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod) and StudentApiKey
in the x-api-key
header.studentData
and send a confirmation email via SES.student-backup-20250706
(section 2.4, 6.5) and send notification emails via SES.s3:GetObject
) for CloudFront to retrieve the content.s3:GetObject
permission is granted to Principal: *
(everyone) to simplify, but it can be restricted with CloudFront OAI (see Note) for better security.You need to complete section 6.1 (create the student-management-website-2025
bucket), section 6.2 (upload index.html
, styles.css
, scripts.js
), section 6.3 (enable Static Website Hosting), section 5 (build the web interface), section 4.1 (create the student
API), section 4.2 (create the StudentApiKey
), section 4.3 (create the StudentUsagePlan
), section 4.4 (create the GET /students method), section 4.5 (create the POST /students method), 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 (link the StudentApiKey
to StudentUsagePlan
), section 3 (create Lambda functions getStudentData
, insertStudentData
, BackupDynamoDBAndSendEmail
, DynamoDB table studentData
, student-backup-20250706
bucket, SES email verification). Ensure your AWS account has s3:PutBucketPolicy
permissions and the AWS region is us-east-1
.
Access the AWS Management Console
student-management-website-2025
bucket, student
API, Lambda functions (getStudentData
, insertStudentData
, BackupDynamoDBAndSendEmail
), DynamoDB studentData
, student-backup-20250706
bucket, and SES. The region is displayed in the top right corner of the AWS Console.Select the student-management-website-2025
Bucket
student-management-website-2025
bucket (created in section 6.1).us-east-1
) and refresh the page.student-management-website-20250706-abc123
).student-management-website-2025
bucket.Access the Permissions Tab
Edit the Bucket Policy
index.html
, styles.css
, scripts.js
have been uploaded (section 6.2) and that Static Website Hosting is enabled with index.html
as the Index document (section 6.3).Edit the Bucket Policy JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::student-management-website-2025/*"
}
]
}
student-management-website-2025
bucket.student-management-website-2025
.Save Changes
arn:aws:s3:::student-management-website-2025/*
).s3:PutBucketPolicy
permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:PutBucketPolicy",
"Resource": "arn:aws:s3:::student-management-website-2025"
}
]
}
Test Website Access
student-management-website-2025
bucket.styles.css
and scripts.js
files should load correctly, and the interface should display as expected.arn:aws:s3:::student-management-website-2025/*
).index.html
, styles.css
, and scripts.js
are uploaded with public-read
permission (section 6.2) or covered by Bucket Policy.index.html
is uploaded in the root directory (section 6.2).index.html
as the Index document (section 6.3).index.html
(e.g., <link href="styles.css">
, <script src="scripts.js">
).Factor | Details |
---|---|
Security | Public access (Principal: "*" ) is suitable for initial testing, but not secure for production. Use CloudFront Origin Access Identity (OAI): - Create an OAI in CloudFront > Origin access identities, and attach it to the CloudFront distribution (section 7). - Re-enable Block public access (except for Block public access for bucket policies) after configuring OAI. - 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-management-website-2025 > Properties > Server access logging, select Enable, and specify a log bucket (e.g., student-web-logs-20250706). Use AWS CLI: aws s3api put-bucket-policy –bucket student-management-website-2025 –policy file://policy.json |
System Integration | Integrate with CloudFront (section 7): - Use the Bucket website endpoint as the Origin. - Set Default root object: index.html . - Configure Viewer protocol policy: Redirect HTTP to HTTPS. Update CORS in API Gateway (section 4.7) with Access-Control-Allow-Origin: https://d12345678.cloudfront.net . |
Integration Testing | Access the Bucket website endpoint to test the interface. After configuring CloudFront, access the CloudFront URL (https://d12345678.cloudfront.net) and check: - POST /students: Save records to DynamoDB studentData , send email via SES. - GET /students: Display table. - POST /backup: Create file in student-backup-20250706 , send email. Use Developer Tools > Network to check API requests. |
Error Handling | 403 Forbidden: Check Bucket Policy ARN, Block all public access (section 6.1), and public-read permission for files (section 6.2). 404 Not Found: Verify index.html is in the root folder, Static Website Hosting is enabled with index.html as the Index document (section 6.3). Incorrect Interface: Check Developer Tools > Console, paths in index.html . CORS: Check Access-Control-Allow-Origin header in Lambda (sections 3.1, 3.2, 3.3) and API Gateway (section 4.7). 429: Check rate/burst/quota limits in StudentUsagePlan (section 4.3). |
Best Practice Tip: Test the Bucket website endpoint immediately after saving the Bucket Policy. Use AWS CLI to automate if applying policies to multiple buckets. Prepare for section 7 (CloudFront configuration) to improve security and support HTTPS.
The Bucket Policy has been configured for the student-management-website-2025
bucket, allowing public access (s3:GetObject
) to serve the web interface. The bucket is now ready to integrate with CloudFront (section 7) for HTTPS and high performance.
Next step: Proceed to Configure CloudFront for Content Distribution to continue configuring!