Phase 5 Deployment Guide
This guide holds every AWS command for the Phase 5 web app, in order: put it online, let GitHub Actions redeploy it, redeploy it from a terminal, and remove it. How the hosting works, and why, is in the Implementation Part 1 section of Phase 5. To run and test the app with no AWS account, see the Development Guide section of Phase 5.
How Do the Sections Fit Together?
flowchart TB
A["Check the Account<br/>tests, login, free names, CORS"] --> B["Build the Files<br/>npm ci, test, build"]
B --> C["Create the Bucket<br/>private, encrypted"]
C --> D["Create CloudFront<br/>access control, then distribution"]
D --> E["Let Only This Distribution<br/>Read the Bucket"]
E --> F["Upload and Check<br/>files, invalidation, served bytes"]
F --> G["Add the CloudFront Address<br/>to the API's CORS List"]
G --> J["Let GitHub Actions Deploy<br/>sign-in provider, role, secret"]
J --> K["Add the Feedback Route<br/>table, role, function, route, limit<br/>(Part 2)"]
K -.-> H["Redeploy After a Change<br/>(the workflow, or a terminal)"]
K -.-> L["Read the Feedback"]
K -.-> I["Remove Everything<br/>(written, not run)"]
- The order avoids a circle. The bucket policy needs the distribution's id, and the distribution needs the bucket. So the bucket and the access control come first, then the distribution, then the policy.
- CORS comes after the distribution, because the CloudFront address only exists once the distribution is created.
- The deploy role comes after that, because its permissions name the bucket and the distribution.
- The feedback route comes last. Part 2 added it to the existing API. It needs nothing from the hosting, and it does not touch the prediction function.
Before the First Command
Run the commands from the project folder unless a step says frontend/. Resource names stay as written. These placeholders stand for values that differ between accounts or runs:
<account-id>: the 12-digit AWS account number. It appears only inside ARNs.<oac-id>: the origin access control's id. In this deployment it isE2S63K0CTCQG24.<distribution-id>: the distribution's id. In this deployment it isE1ZD23BE9RM77L.<distribution-domain>: the distribution's address. In this deployment it isd1nubiunzfwm0q.cloudfront.net.<invalidation-id>and<etag>: values printed by the command before the one that uses them.
What must be true first:
- Phase 4 is deployed, and the API at
https://9awodatqc5.execute-api.us-east-1.amazonaws.comanswers/health. - AWS CLI version 2 (2.35.9 here), with default credentials for the account that owns the API, in
us-east-1. CloudFront is a global service and ignores--region. It is passed anyway, so every line looks alike. - Node.js and npm, as in the Development Guide.
Heads up: this account holds another project's CloudFront resources, the distribution E14C2E7GBRK0V1 and the origin access control sb-prod-site-oac. They are not part of this project. Every command here names this project's own ids, and none of them touches those two.
Check the Account
- Run both test suites (
make pytestandmake web-testdo the same). The Python tests give 95 passed. Run the app tests fromfrontend/. They give 65 passed, or 63 passed and 2 skipped without the expected files inbuild/.
python -m pytest -q
npm test
- Confirm the credentials work. The command prints your identity's ARN, which includes the account number.
aws sts get-caller-identity --query Arn --output text --region us-east-1
- Confirm the bucket name is free. The expected result is an error with 404 Not Found. A 403 means another account owns the name, and a different name is needed.
aws s3api head-bucket --bucket 510-m3-nfl-web-app --region us-east-1
- Confirm there is no access control named
510-m3-nfl-web-app-oac, and no distribution with the comment510-m3-nfl-web-app.
aws cloudfront list-origin-access-controls --query 'OriginAccessControlList.Items[].{Id:Id,Name:Name}' --region us-east-1
aws cloudfront list-distributions --query 'DistributionList.Items[].{Id:Id,Domain:DomainName,Comment:Comment}' --region us-east-1
- Read the API's CORS setting. Before this phase it allows only
http://localhost:5173, the methodsPOST,GET, andOPTIONS, the headercontent-type, and a max age of 300.
aws apigatewayv2 get-api --api-id 9awodatqc5 --region us-east-1 --query CorsConfiguration
- Save a copy of that setting for the removal steps.
cat > build/cors-localhost-only.json <<'EOF'
{
"AllowOrigins": ["http://localhost:5173"],
"AllowMethods": ["POST", "GET", "OPTIONS"],
"AllowHeaders": ["content-type"],
"MaxAge": 300
}
EOF
- Confirm the API is up.
curl -sS -w '\nHTTP %{http_code}\n' https://9awodatqc5.execute-api.us-east-1.amazonaws.com/health
Build the Files
- From
frontend/, install the exact package versions, run the tests, and build.
npm ci
npm test
npm run build
- Record the fingerprint of each built file. The upload is checked against these values later. The Part 1 build was
index.html(1,105 bytes),assets/index-KSsdwuOf.js(233,372 bytes),assets/index-yAxaDZ6u.css(10,307 bytes), and 12.woff2font files. The commands below use those Part 1 names as examples. Every new build, including Part 2's five-tab site, gets new script and stylesheet names, so use the ones in your owndist/assets/.
shasum -a 256 dist/index.html dist/assets/*
Create the Bucket
- Create the bucket, block all public access, turn on encryption, and tag it.
us-east-1takes no location setting.
aws s3api create-bucket --bucket 510-m3-nfl-web-app --region us-east-1
aws s3api put-public-access-block --bucket 510-m3-nfl-web-app --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true --region us-east-1
aws s3api put-bucket-encryption --bucket 510-m3-nfl-web-app --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}' --region us-east-1
aws s3api put-bucket-tagging --bucket 510-m3-nfl-web-app --tagging 'TagSet=[{Key=project,Value=510-m3}]' --region us-east-1
- Read the settings back: all four blocks
true,AES256, and ownershipBucketOwnerEnforced(the default, which turns off per-file permissions).
aws s3api get-public-access-block --bucket 510-m3-nfl-web-app --region us-east-1
aws s3api get-bucket-encryption --bucket 510-m3-nfl-web-app --region us-east-1
aws s3api get-bucket-ownership-controls --bucket 510-m3-nfl-web-app --region us-east-1
Create CloudFront
- Create the origin access control. Record the
Idit prints as<oac-id>.
aws cloudfront create-origin-access-control --origin-access-control-config 'Name=510-m3-nfl-web-app-oac,Description=CloudFront signs its requests to the 510-m3-nfl-web-app bucket,SigningProtocol=sigv4,SigningBehavior=always,OriginAccessControlOriginType=s3' --region us-east-1
- Write the distribution's settings, with the real
<oac-id>. The cache policy id658327ea-f89d-4fab-a63d-7e88639e58f6is the AWS managed policyManaged-CachingOptimized. It follows each file'sCache-Controlheader, so the upload in step 18 sets how long files are kept.
cat > build/cloudfront-config.json <<'EOF'
{
"DistributionConfig": {
"CallerReference": "510-m3-nfl-web-app-1",
"Comment": "510-m3-nfl-web-app",
"Enabled": true,
"DefaultRootObject": "index.html",
"HttpVersion": "http2and3",
"IsIPV6Enabled": true,
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "510-m3-nfl-web-app-s3",
"DomainName": "510-m3-nfl-web-app.s3.us-east-1.amazonaws.com",
"OriginAccessControlId": "<oac-id>",
"S3OriginConfig": { "OriginAccessIdentity": "" }
}
]
},
"DefaultCacheBehavior": {
"TargetOriginId": "510-m3-nfl-web-app-s3",
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": {
"Quantity": 2,
"Items": ["GET", "HEAD"],
"CachedMethods": { "Quantity": 2, "Items": ["GET", "HEAD"] }
},
"Compress": true,
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6"
},
"ViewerCertificate": { "CloudFrontDefaultCertificate": true }
},
"Tags": {
"Items": [
{ "Key": "project", "Value": "510-m3" },
{ "Key": "Name", "Value": "510-m3-nfl-web-app" }
]
}
}
EOF
- Create the distribution, from the project folder, so the
file://path is found. Record theIdas<distribution-id>and theDomainNameas<distribution-domain>. Run it once. The fixedCallerReferencemakes a second run fail withDistributionAlreadyExists, and not create a second distribution.
aws cloudfront create-distribution-with-tags --distribution-config-with-tags file://build/cloudfront-config.json --region us-east-1
- Wait until it is deployed, which takes a few minutes, then read the settings back.
aws cloudfront wait distribution-deployed --id <distribution-id> --region us-east-1
aws cloudfront get-distribution-config --id <distribution-id> --region us-east-1
Let Only This Distribution Read the Bucket
- Write the bucket policy, with the real account and distribution ids. It allows CloudFront to read files only when the request comes from this one distribution. Blocking public policies does not block this one, because a policy that names one distribution is not public.
cat > build/bucket-policy.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontReadFor510M3NflWebApp",
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::510-m3-nfl-web-app/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::<account-id>:distribution/<distribution-id>"
}
}
}
]
}
EOF
- Apply it, and confirm the bucket is not public (
"IsPublic": false).
aws s3api put-bucket-policy --bucket 510-m3-nfl-web-app --policy file://build/bucket-policy.json --region us-east-1
aws s3api get-bucket-policy-status --bucket 510-m3-nfl-web-app --region us-east-1
Upload and Check
- Upload the hashed files first and
index.htmllast, so the page is never served before the files it names. The hashed files are kept for a year, andindex.htmlis checked again on every load.
aws s3 cp frontend/dist/assets/ s3://510-m3-nfl-web-app/assets/ --recursive --cache-control "public, max-age=31536000, immutable" --region us-east-1
aws s3 cp frontend/dist/index.html s3://510-m3-nfl-web-app/index.html --cache-control "no-cache" --content-type "text/html; charset=utf-8" --region us-east-1
- Tell CloudFront to drop its copies of the page, under both the bare address and
/index.html. Record theInvalidation.Idas<invalidation-id>, and wait for it.
aws cloudfront create-invalidation --distribution-id <distribution-id> --paths "/index.html" "/" --region us-east-1
aws cloudfront wait invalidation-completed --distribution-id <distribution-id> --id <invalidation-id> --region us-east-1
- Check the files in the bucket. Expect every file in
frontend/dist/, plus any earlier builds' hashed files.index.htmlhastext/html; charset=utf-8andno-cache. The stylesheet hastext/css, the script hastext/javascript, and each font hasfont/woff2, all withpublic, max-age=31536000, immutable.
aws s3 ls s3://510-m3-nfl-web-app --recursive --region us-east-1
aws s3api head-object --bucket 510-m3-nfl-web-app --key index.html --region us-east-1
aws s3api head-object --bucket 510-m3-nfl-web-app --key assets/index-KSsdwuOf.js --region us-east-1
aws s3api head-object --bucket 510-m3-nfl-web-app --key assets/inter-latin-wght-normal-Dx4kXJAl.woff2 --region us-east-1
- Check that CloudFront serves the tested bytes. Each fingerprint must equal the one from step 9.
/and/index.htmlare both theindex.htmlfile.curlasks for no compression by default, so the bytes are the file itself.
curl -sS https://<distribution-domain>/ | shasum -a 256
curl -sS https://<distribution-domain>/index.html | shasum -a 256
for f in frontend/dist/assets/*; do printf '%s ' "$(basename "$f")"; curl -sS "https://<distribution-domain>/assets/$(basename "$f")" | shasum -a 256; done
- Check the rest of the setup. Expect, in order:
content-encoding: gzip; status 301 withlocation: https://<distribution-domain>/; status 403 for aPOST; status 403 for both direct S3 addresses; and status 403 for a missing path.
curl -sS -D - -o /dev/null -H "Accept-Encoding: gzip" https://<distribution-domain>/assets/index-KSsdwuOf.js
curl -sS -D - -o /dev/null http://<distribution-domain>/
curl -sS -o /dev/null -w '%{http_code}\n' -X POST https://<distribution-domain>/
curl -sS -o /dev/null -w '%{http_code}\n' https://510-m3-nfl-web-app.s3.us-east-1.amazonaws.com/index.html
curl -sS -o /dev/null -w '%{http_code}\n' https://510-m3-nfl-web-app.s3.amazonaws.com/index.html
curl -sS -o /dev/null -w '%{http_code}\n' https://<distribution-domain>/no-such-file
- Confirm the page would still be blocked. Before the next section, a preflight from the CloudFront address returns 204 with no
access-control-allow-originheader.
curl -sS -D - -o /dev/null -X OPTIONS https://9awodatqc5.execute-api.us-east-1.amazonaws.com/predict -H "Origin: https://<distribution-domain>" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: content-type"
Add the CloudFront Address to the API's CORS List
- Write the new setting with both origins, and apply it. The update replaces the whole setting, so the local origin must be written again. The origin has no trailing slash.
cat > build/cors.json <<'EOF'
{
"AllowOrigins": ["http://localhost:5173", "https://<distribution-domain>"],
"AllowMethods": ["POST", "GET", "OPTIONS"],
"AllowHeaders": ["content-type"],
"MaxAge": 300
}
EOF
aws apigatewayv2 update-api --api-id 9awodatqc5 --cors-configuration file://build/cors.json --region us-east-1
aws apigatewayv2 get-api --api-id 9awodatqc5 --region us-east-1 --query CorsConfiguration
- Check the preflight from each origin. The CloudFront address and
http://localhost:5173each get 204 with their ownaccess-control-allow-origin.http://example.comgets 204 with no such header.
curl -sS -D - -o /dev/null -X OPTIONS https://9awodatqc5.execute-api.us-east-1.amazonaws.com/predict -H "Origin: https://<distribution-domain>" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: content-type"
curl -sS -D - -o /dev/null -X OPTIONS https://9awodatqc5.execute-api.us-east-1.amazonaws.com/predict -H "Origin: http://localhost:5173" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: content-type"
curl -sS -D - -o /dev/null -X OPTIONS https://9awodatqc5.execute-api.us-east-1.amazonaws.com/predict -H "Origin: http://example.com" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: content-type"
- Send a real prediction with the CloudFront origin. It returns status 200,
access-control-allow-origin: https://<distribution-domain>, and{"prediction":1,"predicted_label":"home win","home_win_probability":0.6376,"model_version":"v1.0"}.
curl -sS -D - -X POST https://9awodatqc5.execute-api.us-east-1.amazonaws.com/predict -H "Origin: https://<distribution-domain>" -H "Content-Type: application/json" -d '{"win_pct_differential":0.3888888888888889,"point_diff_per_game_differential":5.9}'
-
Run the every-matchup check from the Development Guide. It must end with
mismatches: 0. -
Check the page in a browser at
https://<distribution-domain>/. Home New England Patriots and away Tennessee Titans shows the Patriots at 63.8% and the Titans at 36.2%. The same team twice shows "Choose two different teams." The browser console shows no CORS error.
Let GitHub Actions Deploy
These steps let the workflow .github/workflows/deploy-web-app.yml deploy with a short-lived AWS sign-in, and no stored access key. How it works is on How Does a Change Reach the Live Web App?. The two policy files go under build/, which git ignores, with the real account number.
- Confirm there is no GitHub sign-in provider and no role with this name yet. The second command should fail with
NoSuchEntity.
aws iam list-open-id-connect-providers --region us-east-1
aws iam get-role --role-name 510-m3-nfl-web-app-deploy-role --region us-east-1
- Create the GitHub sign-in provider. AWS fills in the certificate thumbprint itself.
aws iam create-open-id-connect-provider --url https://token.actions.githubusercontent.com --client-id-list sts.amazonaws.com --tags Key=project,Value=510-m3 --region us-east-1
- Write the trust policy. It lets only runs on
mainof this repository use the role. The subject has GitHub's owner id and repository id after each name, which is the form the live role uses.
cat > build/web-app-deploy-trust.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::<account-id>:oidc-provider/token.actions.githubusercontent.com" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:jconnors23@59714706/510-m3-nfl-prediction-analytics@1458181148:ref:refs/heads/main"
}
}
}
]
}
EOF
- Create the role, with sessions of at most an hour.
aws iam create-role --role-name 510-m3-nfl-web-app-deploy-role --assume-role-policy-document file://build/web-app-deploy-trust.json --description "GitHub Actions deploys the web app to S3 and CloudFront" --max-session-duration 3600 --tags Key=project,Value=510-m3 --region us-east-1
- Write the permissions and attach them. They allow uploading files into the web app bucket, and creating and reading invalidations on this one distribution. Nothing else.
cat > build/web-app-deploy-policy.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "UploadTheBuild",
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::510-m3-nfl-web-app/*"
},
{
"Sid": "RefreshThePage",
"Effect": "Allow",
"Action": ["cloudfront:CreateInvalidation", "cloudfront:GetInvalidation"],
"Resource": "arn:aws:cloudfront::<account-id>:distribution/<distribution-id>"
}
]
}
EOF
aws iam put-role-policy --role-name 510-m3-nfl-web-app-deploy-role --policy-name 510-m3-nfl-web-app-deploy --policy-document file://build/web-app-deploy-policy.json --region us-east-1
- Read both documents back.
aws iam get-role --role-name 510-m3-nfl-web-app-deploy-role --query Role.AssumeRolePolicyDocument --region us-east-1
aws iam get-role-policy --role-name 510-m3-nfl-web-app-deploy-role --policy-name 510-m3-nfl-web-app-deploy --region us-east-1
- Save the role's address as the repository secret
AWS_WEB_APP_DEPLOY_ROLE_ARN. The first command prints it. Paste it into GitHub under Settings, Secrets and variables, Actions, or use the second command with the GitHub CLI.
aws iam get-role --role-name 510-m3-nfl-web-app-deploy-role --query Role.Arn --output text --region us-east-1
gh secret set AWS_WEB_APP_DEPLOY_ROLE_ARN --repo jconnors23/510-m3-nfl-prediction-analytics
- Merge
.github/workflows/deploy-web-app.ymlintomain. The merge changes the workflow file, so it starts the first run. Watch it in the Actions tab. The summary lists the deployed files and says whether the served bytes matched. It is written even when a step fails, withnot checkedfor a step that did not run.
Add the Feedback Route
These steps add POST /feedback to the existing API, for the Feedback tab. How it works is in the feedback route section of Frontend and Backend Connection. <integration-id> and <route-id> are printed by the commands that create them. In this deployment they are y286yp2 and lte10if.
- Confirm nothing exists yet. The first three commands should fail with "not found", and the last should list only
POST /predictandGET /health.
aws dynamodb describe-table --table-name 510-m3-nfl-feedback --region us-east-1
aws lambda get-function --function-name 510-m3-nfl-feedback-api --region us-east-1
aws iam get-role --role-name 510-m3-nfl-feedback-api-role --region us-east-1
aws apigatewayv2 get-routes --api-id 9awodatqc5 --query 'Items[].RouteKey' --region us-east-1
- Create the table, keyed by
feedback_idand billed per request, then wait until it is ready.
aws dynamodb create-table --table-name 510-m3-nfl-feedback --attribute-definitions AttributeName=feedback_id,AttributeType=S --key-schema AttributeName=feedback_id,KeyType=HASH --billing-mode PAY_PER_REQUEST --tags Key=project,Value=510-m3 --region us-east-1
aws dynamodb wait table-exists --table-name 510-m3-nfl-feedback --region us-east-1
- Write the function's trust policy (only Lambda can use the role) and its one permission (write one item to this table), with the real account number.
cat > build/feedback-trust.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole" }
]
}
EOF
cat > build/feedback-write.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SaveFeedback",
"Effect": "Allow",
"Action": "dynamodb:PutItem",
"Resource": "arn:aws:dynamodb:us-east-1:<account-id>:table/510-m3-nfl-feedback"
}
]
}
EOF
- Create the role, let it write logs, and attach the one permission.
aws iam create-role --role-name 510-m3-nfl-feedback-api-role --assume-role-policy-document file://build/feedback-trust.json --description "The feedback function writes one item to its table" --tags Key=project,Value=510-m3 --region us-east-1
aws iam attach-role-policy --role-name 510-m3-nfl-feedback-api-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole --region us-east-1
aws iam put-role-policy --role-name 510-m3-nfl-feedback-api-role --policy-name 510-m3-nfl-feedback-write --policy-document file://build/feedback-write.json --region us-east-1
- Build the zip. It holds only
src/api/feedback_handler.py, at that path, because the function uses theboto3that Lambda already provides.
rm -f build/510-m3-nfl-feedback-api.zip
zip build/510-m3-nfl-feedback-api.zip src/api/feedback_handler.py
- Create the function, then wait until it is active. If it fails because the new role cannot be used yet, wait a few seconds and run it again.
aws lambda create-function --function-name 510-m3-nfl-feedback-api --runtime python3.13 --architectures arm64 --handler src.api.feedback_handler.handler --role arn:aws:iam::<account-id>:role/510-m3-nfl-feedback-api-role --zip-file fileb://build/510-m3-nfl-feedback-api.zip --memory-size 256 --timeout 5 --environment "Variables={FEEDBACK_TABLE=510-m3-nfl-feedback}" --tags project=510-m3 --region us-east-1
aws lambda wait function-active-v2 --function-name 510-m3-nfl-feedback-api --region us-east-1
- Connect the route. Create the integration and note its id, create the route, and let only this route call the function.
aws apigatewayv2 create-integration --api-id 9awodatqc5 --integration-type AWS_PROXY --integration-uri arn:aws:lambda:us-east-1:<account-id>:function:510-m3-nfl-feedback-api --payload-format-version 2.0 --query IntegrationId --output text --region us-east-1
aws apigatewayv2 create-route --api-id 9awodatqc5 --route-key "POST /feedback" --target integrations/<integration-id> --region us-east-1
aws lambda add-permission --function-name 510-m3-nfl-feedback-api --statement-id 510-m3-nfl-feedback-http-api --action lambda:InvokeFunction --principal apigateway.amazonaws.com --source-arn "arn:aws:execute-api:us-east-1:<account-id>:9awodatqc5/*/POST/feedback" --region us-east-1
- Limit that route only, to 1 request a second with bursts of 5, then read the stage back. Only
POST /feedbackshould have a limit.
aws apigatewayv2 update-stage --api-id 9awodatqc5 --stage-name '$default' --route-settings '{"POST /feedback":{"ThrottlingBurstLimit":5,"ThrottlingRateLimit":1}}' --region us-east-1
aws apigatewayv2 get-stage --api-id 9awodatqc5 --stage-name '$default' --query RouteSettings --region us-east-1
- Check the route. A 5-character message should return 422 with "The message must be 10 to 1,000 characters." The existing CORS setting already allows
POSTwithcontent-typefrom the CloudFront address, so nothing changes there.
curl -sS -w '\nHTTP %{http_code}\n' -X POST https://9awodatqc5.execute-api.us-east-1.amazonaws.com/feedback -H "Content-Type: application/json" -d '{"category":"general","rating":null,"message":"short","website":""}'
- After the first call, tag the function's log group and keep its logs for 14 days.
aws logs tag-resource --resource-arn arn:aws:logs:us-east-1:<account-id>:log-group:/aws/lambda/510-m3-nfl-feedback-api --tags project=510-m3 --region us-east-1
aws logs put-retention-policy --log-group-name /aws/lambda/510-m3-nfl-feedback-api --retention-in-days 14 --region us-east-1
- Confirm the prediction function did not change. Its
CodeSha256should still beIU5bJH9pTL+rF/uEXMUAp+Eo/mik2abfaSasBXPOgbk=.
aws lambda get-function-configuration --function-name 510-m3-nfl-predict-api --query CodeSha256 --output text --region us-east-1
Read the Feedback
The feedback is read with the AWS command line. There is no page for it. The first command counts the items. The second lists every item with its time, category, rating, and message.
aws dynamodb scan --table-name 510-m3-nfl-feedback --select COUNT --query Count --region us-east-1
aws dynamodb scan --table-name 510-m3-nfl-feedback --query 'Items[].{When:submitted_at.S,Category:category.S,Rating:rating.N,Message:message.S}' --output table --region us-east-1
To change the feedback function's code, rebuild the zip with step 41, then update the function. Its CodeSha256 changes, and the prediction function's does not.
aws lambda update-function-code --function-name 510-m3-nfl-feedback-api --zip-file fileb://build/510-m3-nfl-feedback-api.zip --region us-east-1
Redeploy After a Change
The workflow does this by itself when a change under frontend/ reaches main. The steps below do the same thing from a terminal, for a deploy without GitHub. The bucket, the distribution, and CORS stay as they are. A pull request that changes frontend/ also runs the Test Web App workflow, which only tests and builds and never deploys. See How Are the Web App's Tests Run on a Pull Request?.
- From
frontend/, install, test, and build. The new script and stylesheet get new hashed names.
npm ci
npm test
npm run build
- Upload the hashed files, then
index.html. Old hashed files stay in the bucket, so a visitor who loaded the previous page a moment earlier still gets the files it names.
aws s3 cp frontend/dist/assets/ s3://510-m3-nfl-web-app/assets/ --recursive --cache-control "public, max-age=31536000, immutable" --region us-east-1
aws s3 cp frontend/dist/index.html s3://510-m3-nfl-web-app/index.html --cache-control "no-cache" --content-type "text/html; charset=utf-8" --region us-east-1
- Invalidate the page, and wait.
aws cloudfront create-invalidation --distribution-id <distribution-id> --paths "/index.html" "/" --region us-east-1
aws cloudfront wait invalidation-completed --distribution-id <distribution-id> --id <invalidation-id> --region us-east-1
- Repeat steps 21 and 28 with the new file names: the served fingerprints must equal the local build, and the known matchup must show the same answer in a browser.
Remove Everything
These commands were written and not run. They remove only this project's deploy role, bucket, distribution, and access control, and put the API's CORS list back to the local origin. The other project's distribution E14C2E7GBRK0V1 is never touched.
To remove only the feedback route, delete these in order. They leave the prediction routes and the hosting in place.
aws apigatewayv2 delete-route --api-id 9awodatqc5 --route-id <route-id> --region us-east-1
aws apigatewayv2 delete-integration --api-id 9awodatqc5 --integration-id <integration-id> --region us-east-1
aws apigatewayv2 update-stage --api-id 9awodatqc5 --stage-name '$default' --route-settings '{}' --region us-east-1
aws lambda delete-function --function-name 510-m3-nfl-feedback-api --region us-east-1
aws logs delete-log-group --log-group-name /aws/lambda/510-m3-nfl-feedback-api --region us-east-1
aws iam delete-role-policy --role-name 510-m3-nfl-feedback-api-role --policy-name 510-m3-nfl-feedback-write --region us-east-1
aws iam detach-role-policy --role-name 510-m3-nfl-feedback-api-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole --region us-east-1
aws iam delete-role --role-name 510-m3-nfl-feedback-api-role --region us-east-1
aws dynamodb delete-table --table-name 510-m3-nfl-feedback --region us-east-1
To remove everything, start with the feedback route above, then remove the deploy role, so no workflow run can upload while the rest is taken down. Then delete the secret AWS_WEB_APP_DEPLOY_ROLE_ARN in GitHub. Delete the GitHub sign-in provider only if nothing else in the account uses it. The last command shows its address.
aws iam delete-role-policy --role-name 510-m3-nfl-web-app-deploy-role --policy-name 510-m3-nfl-web-app-deploy --region us-east-1
aws iam delete-role --role-name 510-m3-nfl-web-app-deploy-role --region us-east-1
aws iam list-open-id-connect-providers --region us-east-1
aws iam delete-open-id-connect-provider --open-id-connect-provider-arn arn:aws:iam::<account-id>:oidc-provider/token.actions.githubusercontent.com --region us-east-1
- Put CORS back to
http://localhost:5173only. Ifbuild/was cleared, recreate the file with step 6 first.
aws apigatewayv2 update-api --api-id 9awodatqc5 --cors-configuration file://build/cors-localhost-only.json --region us-east-1
- Turn the distribution off. A distribution must be off before it can be deleted. The first command saves its settings and prints the
ETagto use as<etag>. The second writes a copy of the settings withEnabledset tofalse. The third sends that copy back.
aws cloudfront get-distribution-config --id <distribution-id> --region us-east-1 > build/distribution-config.json
python -c "import json; d = json.load(open('build/distribution-config.json')); print(d['ETag']); c = d['DistributionConfig']; c['Enabled'] = False; json.dump(c, open('build/distribution-disabled.json', 'w'), indent=2)"
aws cloudfront update-distribution --id <distribution-id> --if-match <etag> --distribution-config file://build/distribution-disabled.json --region us-east-1
aws cloudfront wait distribution-deployed --id <distribution-id> --region us-east-1
- Delete the distribution. Turning it off changed its
ETag, so read the new one first.
aws cloudfront get-distribution --id <distribution-id> --query ETag --output text --region us-east-1
aws cloudfront delete-distribution --id <distribution-id> --if-match <etag> --region us-east-1
- Delete the access control, with its own
ETag.
aws cloudfront get-origin-access-control --id <oac-id> --query ETag --output text --region us-east-1
aws cloudfront delete-origin-access-control --id <oac-id> --if-match <etag> --region us-east-1
- Empty the bucket and delete it.
aws s3 rm s3://510-m3-nfl-web-app --recursive --region us-east-1
aws s3api delete-bucket --bucket 510-m3-nfl-web-app --region us-east-1