From 2a5ef60306e241b835461965299ef645f35fba52 Mon Sep 17 00:00:00 2001 From: Rodrigues Date: Thu, 4 Mar 2021 00:20:04 -0800 Subject: [PATCH] adding deployment guide --- README.md | 5 +- docs/deployment_guide.md | 88 ++++++++++++++++++++++ samconfig.toml | 11 +++ src/backend/template.yaml => template.yaml | 26 +++---- 4 files changed, 114 insertions(+), 16 deletions(-) create mode 100644 docs/deployment_guide.md create mode 100644 samconfig.toml rename src/backend/template.yaml => template.yaml (96%) diff --git a/README.md b/README.md index 4c7b0ad..8326bcc 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,8 @@ A solution prototype utilizing AWS-managed Natural Language Processing (NLP) ser ## High level Architecture ![alt text](src/backend/media/AWS_Diagram.png) -## Stack Documentation -[Backend Documentation](src/backend/README.md) \ -[Frontend Documentation](src/frontend/README.md) +## Deployment + deploy this solution into your AWS Account please follow our [Deployment Guide](doc/deployment_guide.md) [UBC CIC Project Page](https://cic.ubc.ca/projects/vch-mri-project-cant-wait/) diff --git a/docs/deployment_guide.md b/docs/deployment_guide.md new file mode 100644 index 0000000..a54c889 --- /dev/null +++ b/docs/deployment_guide.md @@ -0,0 +1,88 @@ +# Requirements +Before you deploy, you must have the following in place: +* [AWS Account](https://aws.amazon.com/account/) +* [GitHub Account](https://github.com/) +* [AWS CLI](https://aws.amazon.com/cli/) +* [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) +* [Amplify CLI installed and configured](https://aws-amplify.github.io/docs/cli-toolchain/quickstart#quickstart) + + +# Step 1: Front-end deployment + +1. Clone and Fork this solution repository. + If you haven't configured Amplify before, configure the Amplify CLI in your terminal as follows: +```bash +amplify configure +``` + +2. In a terminal from the project root directory, enter the following command selecting the IAM user of the AWS Account you will deploy this application from. (accept all defaults): + +```bash +amplify init +``` + +3. Deploy the resourse to your AWS Account using the command: +```bash +amplify push +``` + +4. Log into the AWS Management Console. +5. Select AWS Amplify and select the **mri-sched** +6. At the *Frontend environments* tab connect to your github account poiting to the forked repo. More informatoin at https://docs.aws.amazon.com/amplify/latest/userguide/deploy-backend.html + +# Step 2: Back-end deployment + +If you don’t have any Amazon EC2 key-pair available [create-your-key-pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#having-ec2-create-your-key-pair). You need the name of the key-pair to proceed. You can list your key-pair executing the following command: +```bash +aws ec2 describe-key-pairs +``` + +1. Store the database username and password at Systems Manager Parameter Store. **Make sure to replace DATABASENAME and DATABASEPWD with the respectives username and password you want to use for the database. +```bash +aws ssm put-parameter --name "/mri-sched/dbuser_ec2" --value "DATABASENAME" --type SecureString --overwrite +aws ssm put-parameter --name "/mri-sched/dbpwd_ec2" --value "DATABASEPWD" --type SecureString --overwrite +``` + +2. In this step we will execute AWS SAM guided configuration by running. +```bash +sam deploy -g --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM +``` + +3. Provide the stack name, region and the key-pair name. For all other question accept the default answer or select *Y*. Below an example: + +``` +Configuring SAM deploy +====================== + + Looking for config file [samconfig.toml] : Not found + + Setting default arguments for 'sam deploy' + ========================================= + Stack Name [sam-app]: mri-sched + AWS Region [us-east-1]: [Your-AWS-REGION] + Parameter CidrBlockVpcParameter [10.0.0.0/16]: + Parameter PrivateSubnetAParameter [10.0.1.0/24]: + Parameter PublicSubnetAParameter [10.0.2.0/24]: + Parameter DBInstanceTypeParameter [t3.medium]: + Parameter AMIID [/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2]: + Parameter KeyName []: [Your-Key-Pair Name] + #Shows you resources changes to be deployed and require a 'Y' to initiate deploy + Confirm changes before deploy [y/N]: y + #SAM needs permission to be able to create roles to connect to the resources in your template + Allow SAM CLI IAM role creation [Y/n]: y + Preprocess may not have authorization defined, Is this okay? [y/N]: y + QueryRules may not have authorization defined, Is this okay? [y/N]: y + QuerySpellchecker may not have authorization defined, Is this okay? [y/N]: y + QueryConjunctions may not have authorization defined, Is this okay? [y/N]: y + QueryWeights may not have authorization defined, Is this okay? [y/N]: y + QuerySpecialtyTags may not have authorization defined, Is this okay? [y/N]: y + DataResults may not have authorization defined, Is this okay? [y/N]: y + Save arguments to configuration file [Y/n]: y + SAM configuration file [samconfig.toml]: + SAM configuration environment [default]: +``` + +4. Confirm the deployment and wait for the stack to be created. + + + diff --git a/samconfig.toml b/samconfig.toml new file mode 100644 index 0000000..52bc97c --- /dev/null +++ b/samconfig.toml @@ -0,0 +1,11 @@ +version = 0.1 +[default] +[default.deploy] +[default.deploy.parameters] +stack_name = "mri-sched" +s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-tv5fka8ymyxs" +s3_prefix = "mri-sched" +region = "us-west-2" +confirm_changeset = true +capabilities = "CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM" +parameter_overrides = "CidrBlockVpcParameter=\"10.0.0.0/16\" PrivateSubnetAParameter=\"10.0.1.0/24\" PublicSubnetAParameter=\"10.0.2.0/24\" DBInstanceTypeParameter=\"t3.medium\" AMIID=\"/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2\" KeyName=\"pdx-kenobi\"" diff --git a/src/backend/template.yaml b/template.yaml similarity index 96% rename from src/backend/template.yaml rename to template.yaml index 9f7df75..a378369 100644 --- a/src/backend/template.yaml +++ b/template.yaml @@ -334,7 +334,7 @@ Resources: Type: AWS::Serverless::LayerVersion Properties: Description: Spell Checker - ContentUri: ./layers/spellchecker.zip + ContentUri: ./src/backend/layers/spellchecker.zip CompatibleRuntimes: - python3.8 - python3.7 @@ -345,7 +345,7 @@ Resources: Type: AWS::Serverless::LayerVersion Properties: Description: Psycopg2 Library - ContentUri: ./layers/psycopg2.zip + ContentUri: ./src/backend/layers/psycopg2.zip CompatibleRuntimes: - python3.8 - python3.7 @@ -356,7 +356,7 @@ Resources: Type: AWS::Serverless::LayerVersion Properties: Description: Postgres Custom Functions - ContentUri: ./layers/postgresql.zip + ContentUri: ./src/backend/layers/postgresql.zip CompatibleRuntimes: - python3.8 - python3.7 @@ -366,7 +366,7 @@ Resources: Preprocess: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/preprocess + CodeUri: ./src/backend/lambdas/preprocess Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -403,7 +403,7 @@ Resources: RuleProcessing: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/rule_processing + CodeUri: ./src/backend/lambdas/rule_processing Layers: - !Ref Psycopg2Layer - !Ref PostgresLayer @@ -420,7 +420,7 @@ Resources: QueryRules: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/query_rules_table + CodeUri: ./src/backend/lambdas/query_rules_table Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -453,7 +453,7 @@ Resources: QuerySpellchecker: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/query_spellchecker + CodeUri: ./src/backend/lambdas/query_spellchecker Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -480,7 +480,7 @@ Resources: QueryConjunctions: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/query_conjunctions + CodeUri: ./src/backend/lambdas/query_conjunctions Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -507,7 +507,7 @@ Resources: QueryWeights: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/query_weights + CodeUri: ./src/backend/lambdas/query_weights Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -540,7 +540,7 @@ Resources: QuerySpecialtyTags: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/query_specialty_tags + CodeUri: ./src/backend/lambdas/query_specialty_tags Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -567,7 +567,7 @@ Resources: UpdateWeights: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/update_word_weights + CodeUri: ./src/backend/lambdas/update_word_weights Layers: - !Ref Psycopg2Layer - !Ref PostgresLayer @@ -584,7 +584,7 @@ Resources: DataResults: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/results + CodeUri: ./src/backend/lambdas/results Events: ExplicitApi: # warning: creates a public endpoint Type: HttpApi @@ -611,7 +611,7 @@ Resources: Thesaurus: Type: AWS::Serverless::Function Properties: - CodeUri: ./lambdas/thesaurus + CodeUri: ./src/backend/lambdas/thesaurus Events: FileUpload: Type: S3