The serverless application connects the CDFA Cannabis Licensing System to DCSS. This README intends to provide instructions to setup a developer machine to run unit tests and deploy the application to AWS.
The following describes the source code organizational structure and naming conventions used for this project.
- src -- All the source code for this project is stored within this directory.
- api -- The source code for the APIs is located here.
- status -- The Lambda and supporting libraries for the status API will have status in the name.
- action-taken -- The Lambda and supporting libraries for the action taken API will have action-taken in the name.
- export -- The source code for the export (to DCSS) functionality is located here.
- action-taken -- The Lambda and supporting libraries for the action taken export will have action-taken in the name.
- action-taken-stats -- The Lambda and supporting libraries for the action taken statistics export will have action-taken-stats in the name.
- outgoing-sftp -- The Lambda and supporting libraries for exporting the flat files to the DCSS sftp server will have outgoing-sftp in the name.
- import -- The source code for the import (from DCSS) functionality is located here.
- delinquency -- The Lambda and supporting libraries for the monthly delinquency import will have delinquency in the name.
- daily-release -- The Lambda and supporting libraries for the daily release import will have daily-release in the name.
- util -- This directory contains reusable libraries that are shared across functional areas.
- api -- The source code for the APIs is located here.
- test -- This directory contains all unit and integration tests for the source code.
The test naming convention will follow the source code followed by
.test.js
for examplesrc/util/encrypt.js
has a corresponding test located attest/util/encrypt.test.js
. Test resources are also stored along side the test files. For example some delinquency import files are stored attest/import/delinquency-import-test-1.txt
. The test resources will end in the.txt
suffix.
- Install GitHub App or favorite git client (https://desktop.github.com/)
- Install node.js v6.10.3 (needs to match AWS Lambda version) and npm (https://nodejs.org/en/download/)
node -v
to verify installation and version
- Install AWS CLI (https://aws.amazon.com/cli/)
aws --version
to verify installation
- Configure AWS CLI
- Create a user and access tokens for unit tests and deployment
- Run
aws configure
and enter in access tokens
- At the root level of this project call the following command to setup the libraries
npm install
- Create the following buckets with read/write/delete privileges for the user created above
- dcss-local-test-action-taken-export-bucket
- dcss-local-test-daily-release-import-bucket
- dcss-local-test-delinquency-import-bucket
- Create the following dynamoDB tables with read/write/delete privileges for the user created above
- dcss-local-test-dcss-table
- primary key
id
- add index
ssnHash-index
on partiion keyssnHash
- add index
stateIdHash-index
on partition keystateIdHash
- primary key
- dcss-local-test-action-taken-table
- primary key
agencyCustomerId
with sort keytimestamp
- add index
actionTakenDate-index
on partition keyactionTakenDate
- add index
actionTakenMonthYear-index
on partition keyactionTakenMonthYear
- primary key
- dcss-local-test-dcss-table
- Create a kms encryption key with the alias
dcss-local-test-key
- Allow the user created above 'User' permissions of the key
Running the tests with Jest
npm test
To run one test use the Jest command
jest {path to the test}
example
jest test/util/action-taken-service.addRecord.test.js
- Environment -- The environment to deploy to example (dev, test, prod)
- HashKey -- The hash key to be used to hash ssn and stateId for searching. This can be something like 'TESTING' for dev and testing. For production use a real hash key. Example
a5a3a27a38ef849dc9016b2ed020c35d
. DON'T LOSE THIS FOR PRODUCTION!! - AwsUsGov -- Should be
aws-us-gov
if running this stack on a non gov cloud AWS you can useaws
- SftpHost -- The sftp host for dcss or a test sftp host for dev/test.
- SftpUser -- The sftp user for dcss or a test sftp user for dev/test.
- SftpPassword -- The sftp password for dcss or a test sftp password for dev/test.
- Package and upload to s3
Example
aws cloudformation package --template-file template.yml --s3-bucket {s3 bucket name} --output-template-file packaged-template.yaml
aws cloudformation package --template-file template.yml --s3-bucket dcss-dev-deployments --output-template-file packaged-template.yaml
- Deploy using CloudFormation.
Example
aws cloudformation deploy --template-file packaged-template.yaml --stack-name dcss-{env} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides Environment={env} HashKey={hashKey} AwsUsGov={aws || aws-us-gov} SftpHost={dcss ftp host} SftpUser={dcss ftp user} SftpPassword={dcss ftp password}
aws cloudformation deploy --template-file packaged-template.yaml --stack-name dcss-dev --capabilities CAPABILITY_NAMED_IAM --parameter-overrides Environment=dev HashKey=TESTING AwsUsGov=aws-us-gov SftpHost=grayquarter.brickftp.com SftpUser=jt@grayquarter.com SftpPassword=c@nn@b15