amag-drm-api v1.0.0
aws-typescript
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Node.js - Install Node.js 10, including the NPM package management tool.
- Docker - Install Docker community edition
How to get your local machine environment setup
Clone your repository from https://bitbucket.org/amagroup/amag-drm-api/src/master
To build and deploy your application for the first time, run the following in your command prompt/terminal:
npm install npm@latest -g
npm install -g typescript
npm install -g cfn-lint
npm install -g cross-env
npm login
Login to NPM to get private repo amag-corlib
Use npm username, password and email
npm login
npm install
During the Development
We use combination of AWS SAM + NodeJS Lambdas + Typescript. So keep running following command all the time in separte terminal window during the development.
Install 'cross-env' using following command
npm install -g --save-dev "cross-env"
Then in a separate terminal window, keep running below command
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
cross-env NODE_ENV=development npm run-script watch
After upadating template.yaml file
Typescript server can't watch .yaml file so in this case you might need to kill 'npm run watch' and rerun again in order to get your changes reflected correctly.
Run DynamoDb locally
docker-compose.yml file contains services we run on docker. One of them is Dynamodb. Copy docker-compose.yml from Infrastructure folder to local folder say d:/Docker. Then run following command from the terminal opened in that folder.
docker-compose up
Dump data tables from AWS into local Dynamo instance.
Please follow instruction in google doc to dump data structures and data from AWS into your local dynamodb instance.
https://docs.google.com/document/d/1F3MRi9y9li4Lyrt2ZiqzkHEphv_dAl9Ukz0V2EQLEjk/edit#heading=h.fd7nbr75gcwe
In the 2nd command I pass an access and secret key - I'm not sure if that's necessary but if it is, you can get those by setting up the local connection in NoSQL workbench, then there should be an option to view those keys. You might just be able to pass anything or leave them blank.
Those commands will include the structure AND data so use the 1st one sparingly since we pay for reads/writes.
Run API Gateway locally
All developers should run API Gateway locally. UI and PostMan should point to local API Gateway.
sam local start-api -p 3001 --docker-network dockers-network --config-file ./samconfig-local.toml
OR
npm run local
Debug the lambdas from local terminal
Lambdas can be debug locally. Make sure the docker is running. Run below command in a terminal from your root project folder. After debug is attached, start lambda function execution in debug mode.
sam local invoke -e events/event.json -d 5858 --docker-network dockers-network <<<lambda function logical name>>>
Run jest test cases
jtest framework is used for test cases. Run following command in terminal of the root folder to run test cases. More info on jest configuration with typescript you can find here : https://basarat.gitbook.io/typescript/intro-1/jest
npm test
Deploy lambda to AWS
Run below command in a terminal from your root project folder.
sam deploy --config-file ./samconfig-dev.toml
Use below command to build all lambdas and deploy to AWS at the same time
sam deploy --config-file ./samconfig-dev.toml
Deploy database to AWS
Infrastructure/database.yaml file contains schema defination of Dynamo tables. Dynamo tables can be created on AWS using following AWS CloudFormation CLI.
aws cloudformation deploy --template-file Infrastructure/database.yaml --stack-name "dev-drm-db"
Seed DynamoDb tables
Infrastructure/seed/sysConfiguration.json file contains seed data. The data can be uploaded to DynamoDb tables using following AWS DynamoDb CLI.
aws dynamodb batch-write-item --request-items file://sysOperationConfiguration.json
aws dynamodb batch-write-item --request-items file://sysSiteConfiguration.json
Create new cognito user
aws cognito-idp admin-create-user --user-pool-id ap-southeast-2_6Y06w0ZKI --username **EMAIL_ID** --temporary-password **TEMP_PASSWORD** --message-action SUPPRESS
Confirm cognito user
aws cognito-idp admin-set-user-password --user-pool-id ap-southeast-2_6Y06w0ZKI --username **EMAIL_ID** --password **TEMP_PASSWORD** --permanent
3 years ago