pharmos-app-service v1.2.51
PharmOS App Service
Documentation
Documentation site can be found here PharmOS App Documentation
Table of Contents
Development
This service is primarily written in Node using the Express framework and is a serverless application that is similar to the Scheduling Service.
Prerequisites
- Docker
>= 19.03.8
- Docker Compose
>= 1.25.4
Docker Desktop for Mac or Docker Desktop for Windows will install both of these for you. DO NOT try to install using brew install docker docker-compose
- you will run into problems.
Setup
Ensure
docker
anddocker-compose
are running and meet the version requirements above$ docker -v Docker version 19.03.8, build afacb8b $ docker-compose -v docker-compose version 1.25.4, build 8d51620a
C:\>docker -v && docker-compose -v Docker version 19.03.8, build afacb8b docker-compose version 1.25.4, build 8d51620a
Configure AWS - Manually or via SSO (instructions below))
Run
yarn install
(see below to ensure that yourNPM_TOKEN
is set)
Manually configuring AWS credentials
- Run
aws configure
and input the following information when prompted. You can configure multiple accounts by setting the--profile
flag (example:aws configure --profile uat
). More info here
region = us-east-1
output = json
You can follow the AWS Access and manually set the AWS credentials in ~/.aws/credentials. Run
vi ~/.aws/credentials
[default] aws_access_key_id = KEY_GOES_HERE aws_secret_access_key = KEY_GOES_HERE aws_session_token = TOKEN_GOES_HERE [dev] aws_access_key_id = KEY_GOES_HERE aws_secret_access_key = KEY_GOES_HERE aws_session_token = TOKEN_GOES_HERE
You will be signed out from previous account if you log into another account from AWS SSO page
Session time out is currently set to 8 hours for both console and CLI
Configuring AWS credentials with sso
Configure SSO.
Run
aws configure sso
.NOTE: ensure you set below values in
~/.aws/config
.[default] sso_start_url = https://medly.awsapps.com/start sso_region = us-east-1 sso_account_id = 592280881349 sso_role_name = Developer region = us-east-1 output = json
Ensure ~/.aws/credentials file is deleted.
Globally install jq Run
brew install jq -g
- Script to rehydrate your AWS session
macOS
Add this script to your ~/.bashrc or ~/.zshrc.
function awscreds() { aws sts get-caller-identity --profile $1 || aws sso login --profile $1 FILE=~/.aws/cli/cache/$(ls -t ~/.aws/cli/cache | head -n 1) export AWS_ACCESS_KEY_ID="$(jq -r '.Credentials.AccessKeyId' $FILE)" AWS_SECRET_ACCESS_KEY="$(jq -r '.Credentials.SecretAccessKey' $FILE)" AWS_SESSION_TOKEN="$(jq -r '.Credentials.SessionToken' $FILE)" }
Anytime you want to rehydrate your AWS session in your terminal Run
awscreds <profile>
eg:awscreds default
Windows
- Make sure you have Python 3 installed, if not, install it here
- Download this file aws_creds_to_env.py
- Run this command. If you not set a profile name, it will take the default one:
python aws_creds_to_env.py {your profile name}
Guides
To setup and run the project locally
These steps will run the project locally
- Configure your environment by adding an
NPM_TOKEN
environment variable:- If you're on a Mac
- You can get the
NPM_TOKEN
from 1Password under 'Shared NPM Token' or you can generate one - (preferred). Set this token in your ~/.zshrc and add below to your .npmrc file. - Run
echo "export NPM_TOKEN=${TOKEN_FROM_1PASS}" >> ~/.zshrc && source ~/.zshrc
- You can get the
- If you're on Windows 10
- Navigate to
Control Panel\System and Security\System
and selectAdvanced system settings
- In the
Advanced
tab, click theEnvironment Variables...
Button - Add new System variable
Variable name: NPM_TOKEN Variable value: <TOKEN_FROM_1PASS>
- Click OK and restart any vsCode and/or CMD instances
- Navigate to
- If on another system, set the
NPM_TOKEN
environment variable appropriately.
- If you're on a Mac
- Copy the contents of
.env.example
into a new file called.env
- Fill in the Okta env values
- Ensure that you have an Okta ID. Then update
src/database/ops/users.csv
with a new row for yourself (UUID, Okta ID, email address, first name, last name). - Run
yarn db:start-local
to run a local PG database in Docker that mimics AWS Aurora - Run
yarn start:dev
to expose local port 3000 to listen for invoked lambda functions and getnodemon
-enabled hot reloading as you edit your code
Database scripts available
API/DB commands
yarn db:start-local
will start the DB containeryarn db:stop-local
will shut down the DB container
DB commands
yarn db:migrate
Will run all migrationsyarn db:seed-run
Will seed database tablesyarn db:refresh
Will drop all tables in schema 'public'
If you need to access the database command line
Local DB access
- Run
yarn docker:exec
- Run
psql -U postgres -d placeholderdb
- This will allow you to write inline SQL queries if needed
- Alternatively, you can use a simple connection string like this (substitute the appropriate credentials):
PAGER="less -S" PGPASSWORD=medly123 psql -h 0.0.0.0 -p 1002 -U postgres pharm-os -x
Running tests
Run yarn test
( Without the server already running )
Killing your process in development
Run yarn stop:dev
Viewing API Docs
Run yarn spec:start
Will open Open API docs on http://127.0.0.1:5001/