AWS Cloud Formation Templates for AMS (Archival Management System)
Use the ams.new_app.json
CloudFormation template. This will create a bunch of
AWS resources used to run AMS.
NOTE: The stack costs $$$ when it's running so make sure you have approval first! When creating a new stack, AWS provides a cost estimate. Right now (Dec 2020) it costs about $140/month.
If successful, you'll have a fully functional stack of AWS resources capable of running the AMS web app.
- Make sure you have the latest version of
ams.new_app.json
from this repository saved to your local machine. - Log into AWS Management Console.
- Navigate to CloudFormation.
- Click "Create stack" >> "With new resources".
- Under "Prerequisite - Prepare template" select "Template is ready".
- Under "Specify template" select "Upload a template file".
- Click "Choose File" and select your local copy of
ams.new_app.json
from step 1, and then click "Next". - Enter a Stack Name, enter values for the parameters:
- All password fields are required.
- ServerName is used for enabling HTTPS and should match the site's domain for verification. If not enabling HTTPS, the default value is fine.
- All other default values should work, but you can adjust them as needed.
- Click "Next" when finished.
- For the "Configure stack options" and "Advanced options", defaults will suffice, but adjust as needed, and click "Next" when finished.
- Review the stack details to make sure it's what you want. To go back, click the "Previous" button at the bottom.
- If the stack looks good to go, check the checkbox labeled with "I acknowledge that AWS CloudFormation might create IAM resources."
- Click "Create Stack". This will kick of an asynchronous process to build the stack. Check the "Events" tab to see the progress. When you see an event in the list whose "Logical ID" is your stack name, and the "Status" is "CREATE_COMPLETE", then the stack is ready.
- Deploy Code
- In the AWS Management console, navigate to CodeDeploy.
- In the left menu, click "Applications".
- Click the AWS "Application" that was created with the CloudFormation template (it should be named the same as your stack).
- Click deployment group for the app (there should be only 1 and be named the same as the stack name, but with "-DG" suffix appended.
- Click the "Create Deployment" button.
- On the "Create Deployment" screen:
- Enter the deployment group that was created as part of the stack. It should be named the same as the stack, with a "-DG" suffix.
- Select the "My application is stored in Github" option.
- Enter the Github token name.
- Enter the repository name: "wgbh-mla/ams".
- Enter the commit hash of the commit you want to deploy. **NOTE:
Due to a branching convention we never truly followed, we do not
currently use the
master
branch, but rather the thedevelop
branch, thus we typically deploy the most recent commit fromdevelop
. This may change, so be sure to consult with developers if you are unsure which branch/commit represents the latest code. - Add an optional description.
Use the ams.restore_from_backups.json
to restore the AMS
If successful, you'll have a fully functioning AMS app with data rolled back to the point-in-time that the snapshots were taken.
- Make sure you have the latest version of
ams.restore_from_snapshot.json
from this repository saved to your local machine. - If you're recreating from an existing instance, ssh in to the active EC2 instance hosting Solr and Fedora to copy their data directories.
- The Fedora data directory is currently located at: /mnt/fedora-data
- The Solr data directory is currently located at: /var/solr/data/ams/data
- Log into AWS Management Console.
- Navigate to RDS
- Click on "DB Instances"
- Create snapshots of the MySQL RDS instances for Rails and Fedora by clicking on "Actions" >> "Take Snapshot"
- Copy the Amazon Resource Names (ARNs).
- Edit your local version of
ams.restore_from_snapshot.json
- Enter the Rails DB ARN where it says: "REPLACE WITH ARN OF RAILS RDS DB SNAPSHOT"
- Enter the Fedora DB ARN where it says: "REPLACE WITH ARN OF FEDORA RDS DB SNAPSHOT"
- Navigate to EC2
- Select the EC2 instance for Fedora
- Click on "Actions" >> "Image and templates" >> "Create Image"
- Defaults are fine.
- Click on "Create Image"
- Copy the AMI ID from the success message (should look like: ami-xxxxxxxxxxxxxxxxx)
- You can also get it from the EC2 interface by clicking on AMIs and finding it by AMI Name
- Edit your local version of ams.restore_from_backups.json
- Enter the AMI ID where it says: "REPLACE WITH IMAGE ID OF AMI CREATED FROM SNAPSHOT OF DataInstance EC2 ROOT VOLUME"
- Navigate to CloudFormation.
- Click "Create stack" >> "With new resources".
- Under "Prerequisite - Prepare template" select "Template is ready".
- Under "Specify template" select "Upload a template file".
- Click "Choose File" and select your local copy of
ams.restore_from_backups.json
from step 1, and then click "Next". - Enter a Stack Name, enter values for the parameters:
- All password fields are required.
- ServerName is used for enabling HTTPS and should match the site's domain for verification. If not enabling HTTPS, the default value is fine.
- All other default values should work, but you can adjust them as needed.
- Click "Next" when finished.
- For the "Configure stack options" and "Advanced options", defaults will suffice, but adjust as needed, and click "Next" when finished.
- Review the stack details to make sure it's what you want. To go back, click the "Previous" button at the bottom.
- If the stack looks good to go, check the checkbox labeled with "I acknowledge that AWS CloudFormation might create IAM resources."
- Click "Create Stack". This will kick of an asynchronous process to build the stack. Check the "Events" tab to see the progress. When you see an event in the list whose "Logical ID" is your stack name, and the "Status" is "CREATE_COMPLETE", then the stack is ready.
- Deploy Code
- In the AWS Management console, navigate to CodeDeploy.
- In the left menu, click "Applications".
- Click the AWS "Application" that was created with the CloudFormation template (it should be named the same as your stack).
- Click deployment group for the app (there should be only 1 and be named the same as the stack name, but with "-DG" suffix appended.
- Click the "Create Deployment" button.
- On the "Create Deployment" screen:
- Enter the deployment group that was created as part of the stack. It should be named the same as the stack, with a "-DG" suffix.
- Select the "My application is stored in Github" option.
- Enter the Github token name.
- Enter the repository name: "wgbh-mla/ams".
- Enter the commit hash of the commit you want to deploy. **NOTE:
Due to a branching convention we never truly followed, we do not
currently use the
master
branch, but rather the thedevelop
branch, thus we typically deploy the most recent commit fromdevelop
. This may change, so be sure to consult with developers if you are unsure which branch/commit represents the latest code. - Add an optional description.
The Cloudformation template includes setup that prepares the AMS web server for encryption with Certbot. As you are creating a new stack or restoring from the old do the following:
- As you are setting the Parameters when launching a stack from a Cloudformation template, set the ServerName so that it matches the domain of your site.
- Creating the stack via the Cloudformation template.
- Deploy the code via CodeDeploy.
- SSH to the web server.
- Run
sudo certbot
to get the certificate.