Objective: Create a CloudFront Distribution to serve static content from the S3 Bucket
student-management-website-2025
(sections 6.1–6.4), using Origin Access Identity (OAI) to restrict bucket access only from CloudFront, enabling Web Application Firewall (WAF) for increased security, and providing HTTPS for the web interface (index.html
,styles.css
,scripts.js
). The distribution will integrate with thestudent
API (stageprod
, section 4.8) to support the GET /students, POST /students, and POST /backup endpoints, usingStudentApiKey
(section 4.2) with CORS (section 4.7).
Principal: "*"
from section 6.4).index.html
, styles.css
, scripts.js
, section 6.2) from the S3 Bucket student-management-website-2025
.student
API (section 4.8) with the Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod) and StudentApiKey
.studentData
and send a confirmation email via SES.student-backup-20250706
(section 6.5) and send notification emails via SES.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 6.4 (configure Bucket Policy), section 6.5 (configure the student-backup-20250706
bucket), 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
). Ensure your AWS account has cloudfront:CreateDistribution
, cloudfront:CreateInvalidation
, s3:PutBucketPolicy
, and the AWS region is us-east-1
for related services.
Access the AWS Management Console
student-management-website-2025
, student
API, Lambda, DynamoDB, and SES are all in us-east-1
.Open the Create Distribution Interface
Configure Distribution Name and Origin
StudentWebsiteDistribution
.
student-management-website-2025
from the list.
student-management-website-2025.s3.amazonaws.com
(the REST API endpoint for S3).student-management-website-2025.s3-website-us-east-1.amazonaws.com
), choose the REST API endpoint (*.s3.amazonaws.com
) to be compatible with OAI.StudentWebsiteOAI
(or any preferred name).student-management-website-2025
.{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontOAI",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity EXXXXXX"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::student-management-website-2025/*"
}
]
}
Principal: "*"
, section 6.4) for better security.Configure Cache Behavior and Security
Configure Settings
www.student-management.com
) if available, requires DNS configuration.index.html
to serve the main file when accessing the CloudFront domain.Project=StudentManagement
, Environment=Production
.Create Distribution
student-management-website-2025.s3.amazonaws.com
.StudentWebsiteOAI
).index.html
.d12345678.cloudfront.net
).Test the Distribution
StudentWebsiteDistribution
).https://d12345678.cloudfront.net
).arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity EXXXXXX
).index.html
, styles.css
, scripts.js
are uploaded to S3 (section 6.2).Principal: "*"
) has been removed (section 6.4).index.html
(section 7.2).index.html
as the Index document (section 6.3).styles.css
or scripts.js
.index.html
(e.g., <link href="styles.css">
, <script src="scripts.js">
).Access-Control-Allow-Origin: https://d12345678.cloudfront.net
.StudentApiKey
, StudentUsagePlan
(section 4.9), and CloudWatch logs for Lambda.Factor | Details |
---|---|
Security | OAI ensures only CloudFront accesses S3. Remove the old public policy (Principal: "*" , section 6.4) and keep Block public access (section 6.1, except Block public access for bucket policies). 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> |
Optimization | Enable CloudFront Standard Logs to track access: In CloudFront > Distribution > General > Logging, select On, specify a log bucket (e.g., student-web-logs-20250706 ). Use AWS CLI: bash <br> aws cloudfront create-distribution --distribution-config file://distribution-config.json <br> |
System Integration | Update CORS in API Gateway (section 4.7) with Access-Control-Allow-Origin: https://d12345678.cloudfront.net . Ensure POST /students, GET /students, POST /backup work with Invoke URL and StudentApiKey . |
Integration Testing | Access the CloudFront URL (https://d12345678.cloudfront.net) and check: - POST /students: Save records, send SES email. - 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 OAI ARN, Bucket Policy, s3:GetObject permission. 404 Not Found: Verify index.html is Default root object, file exists in S3. Incorrect Interface: Check Developer Tools > Console, paths in index.html . CORS: Check Access-Control-Allow-Origin header in Lambda (section 3) and API Gateway (section 4.7). 429: Check rate/burst/quota limits in StudentUsagePlan (section 4.3). |
Best Practice Tip: Test the CloudFront URL immediately after the Enabled status. Create invalidation (section 7.3) if updating files in S3. Use AWS CLI to automate configuration.
The CloudFront Distribution has been created with OAI and WAF, distributing content from student-management-website-2025
over HTTPS. The system is ready to integrate with the student
API and test the interface.
Next step: Proceed to Configure Default Root Object to continue configuration!