Objective: Create an Invalidation for the CloudFront Distribution
StudentWebsiteDistribution
(section 7.1) to refresh the cache content, ensuring the static files (index.html
,styles.css
,scripts.js
, section 6.2) from the S3 Bucketstudent-management-website-2025
are updated on the CloudFront domain (e.g., https://d12345678.cloudfront.net). This ensures that users see the latest version of the web interface when files are modified, while maintaining integration with thestudent
API (stageprod
, section 4.8) to perform functions such as saving, viewing, and backing up data. After creating the invalidation, check the Deploying status and the interface via the Distribution domain name.
index.html
, styles.css
, scripts.js
) are updated, old cache can cause users to see outdated versions./*
path to invalidate all cache content in the distribution, suitable when updating multiple files or when the specific file changed is not known (e.g., after uploading a new version of styles.css
or scripts.js
from section 6.2).index.html
, styles.css
, scripts.js
, section 6.2) from the S3 Bucket student-management-website-2025
(sections 6.1–6.4) through Origin Access Identity (OAI) (section 7.1) to restrict access.student
API (section 4.8) with the Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod) and StudentApiKey
(section 4.2).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 7.1 (create the CloudFront Distribution StudentWebsiteDistribution
), section 7.2 (configure the Default Root Object), 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:CreateInvalidation
, s3:GetObject
, 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 in us-east-1
.Select the CloudFront Distribution
StudentWebsiteDistribution
(created in section 7.1).
E...
and the Domain name is of the form d12345678.cloudfront.net
.Access the Invalidations Tab
StudentWebsiteDistribution
, select the Invalidations tab (usually at the top of the page, next to General, Behaviors, etc.).Create Invalidation
/*
.
/*
path instructs CloudFront to invalidate all cache content in the distribution, ensuring all files (index.html
, styles.css
, scripts.js
) are fetched as the latest version from S3.styles.css
or scripts.js
from section 6.2)./index.html
, /styles.css
) to reduce invalidation costs./*
Path for Invalidation.Check Invalidation Status
cloudfront:CreateInvalidation
permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::<AWS_ACCOUNT_ID>:distribution/<DISTRIBUTION_ID>"
}
]
}
<AWS_ACCOUNT_ID>
and <DISTRIBUTION_ID>
with actual values (find in CloudFront > Distributions).Access Distribution Domain Name to Verify
StudentWebsiteDistribution
(e.g., https://d12345678.cloudfront.net
).index.html
, styles.css
, and scripts.js
(if updated in S3, section 6.2).styles.css
(e.g., change the gradient color) or index.html
(e.g., add a new field) to the S3 Bucket student-management-website-2025
(section 6.2)./*
.Verify Interface and API Functionality
https://d12345678.cloudfront.net
):
studentid
, name
, class
, birthdate
, email
) works correctly.studentData
and the confirmation email is sent via SES.
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"}'
curl -X GET https://abc123.execute-api.us-east-1.amazonaws.com/prod/students \
-H "x-api-key: xxxxxxxxxxxxxxxxxxxx"
student-backup-20250706
and the notification email is sent via SES.
curl -X POST https://abc123.execute-api.us-east-1.amazonaws.com/prod/backup \
-H "x-api-key: xxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json"
/*
if needed.index.html
, styles.css
, scripts.js
) are uploaded to S3 correctly (section 6.2).{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontOAI",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity <OAI_ID>"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::student-management-website-2025/*"
}
]
}
index.html
, styles.css
, and scripts.js
are uploaded to S3 (section 6.2).index.html
in CloudFront > Distributions > General.index.html
as the Index document in S3.styles.css
or scripts.js
.index.html
(e.g., <link href="styles.css">
, <script src="scripts.js">
) match the directory structure in S3.Access-Control-Allow-Origin: https://d12345678.cloudfront.net
.scripts.js
sends the API request with the correct Invoke URL (e.g., https://abc123.execute-api.us-east-1.amazonaws.com/prod) and header x-api-key: <StudentApiKey>
.StudentApiKey
, StudentUsagePlan
(section 4.9), and CloudWatch logs for Lambda.Factor | Details |
---|---|
Security | Ensure the Bucket Policy only allows OAI access to S3 (section 7.1). 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> |
Optimization | Enable CloudFront Standard Logs to track access: In CloudFront > Distribution > General > Logging, select On, and specify a log bucket (e.g., student-web-logs-20250706 ). Use AWS CLI to automate invalidation: bash <br> aws cloudfront create-invalidation --distribution-id <DISTRIBUTION_ID> --paths "/*" <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 | Content not updated: Check invalidation status, S3 files, and Bucket Policy. 403 Forbidden: Check OAI, Bucket Policy, s3:GetObject permission. 404 Not Found: Verify index.html is Default Root Object, file exists in S3. 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: Create an invalidation whenever updating files in S3. Test the CloudFront URL immediately after the Completed status. Use AWS CLI to automate invalidations:
aws cloudfront create-invalidation --distribution-id <DISTRIBUTION_ID> --paths "/*"
.
The Invalidation has been created for CloudFront Distribution StudentWebsiteDistribution
, ensuring cache content is refreshed, and the web interface displays the latest version from S3. The system is integrated with the student
API and is ready for operation.
Next step: Proceed to Set Up System Backup to begin system backup deployment!