...
- Copy the updated prod.yaml config to our infrastructure-as-code bucket and get the versioned URL for the file as shown here.
aws s3 cp server/cfn/prod.yaml s3://jcsda-usaf-iac-artifacts/r2d2/prod.yaml
file_version=$(aws s3api list-object-versions \
--bucket jcsda-usaf-iac-artifacts \
--prefix "r2d2/prod.yaml" \
| jq -r '.Versions[] | select(.IsLatest==true) | .VersionId')
echo "https://jcsda-usaf-iac-artifacts.s3.us-east-2.amazonaws.com/r2d2/prod.yaml?versionId=${file_version}" - Go to the CloudFormation stack "r2d2-api-prod" in the AWS console (or use quick-ref link above) and click "Update".
- In the update menu, select "Replace existing template" and enter the URL generated in the first step. Change any parameters and review deploy options.
- Review the change log and ensure that EC2 instances and RDS instances are not replaced.
- Monitor the CloudFormation rollout in console and ensure it executes to completion.
Viewing Service and Error Logs
Logs for all API server replicas can be found under the "r2d2." log groups in AWS CloudWatch [direct link]. The CloudWatch log exports are on a half-our schedule so expect a delay between an error and finding the logs in CloudWatch. Each server writes logs to /var/log/gunicorn/ and those can be viewed in realtime if you are logged in.
Build and publish API server binaries
...
| Code Block |
|---|
# If logged into the server, log out now and log back in to reset the shell environment # From your developer machine log into the server aws ssm start-session --target i-0a0612957e4895917 --region us-east-2 # Enable the bash shell # This process needs to be completed as root sudo su - # Get local credentials for our ECR repository. aws ecr get-login-password --region us-east-2 \ | docker login --username AWS \ --password-stdin 747101682576.dkr.ecr.us-east-2.amazonaws.com # Pull the latest Docker container docker pull 747101682576.dkr.ecr.us-east-2.amazonaws.com/r2d2-server:prod # Stop the running service. systemctl stop r2d2.service # If Removenecessary, theedit current container. docker rm r2d2-api-service # Re-start the prod service container. docker run -d --name r2d2-api-service -p 80:80 \ -e MYSQL_USER='r2d2' \ -e MYSQL_DATABASE='r2d2' \ -e MYSQL_HOST='r2d2-api-prod-rdsinstance-eja4eofrohvy.cg24vilqoa8w.us-east-2.rds.amazonaws.com' \ 747101682576.dkr.ecr.us-east-2.amazonaws.com/r2d2-server:prod \ run_r2d2_app --port 80 --nodebugservice definition file: /etc/systemd/system/r2d2.service # Do this only if docker arguments or environment variables have changed. # If updating this file you will need to run `systemctl daemon-reload` to # load in updates to the service. # Restart the systemd service. systemctl start r2d2.service # Check the status of the service docker ps # Sample output from the production server CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cd8745ac7561 747101682576.dkr.ecr.us-east-2.amazonaws.com/r2d2-server:prod "run_r2d2_app --port…" 47 seconds ago Up 46 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp r2d2-api-service # Check the output logs docker logs -f r2d2-api-service |
...