- Setup
- AWS SSO Configuration
- Environment Variables
- Application Tasks
- Testing Lambda Functions Locally Without Docker
- Deployment Notes
- Lambda Functions
- Chiron (removed)
- Chronos
- Thanos
- Portal Data Sync
- Documentation
The Expense App API is written in Node.js v20.x+.
Download and install Node.js v20.x from: https://nodejs.org/en/ or https://nodejs.org/dist/latest-v20.x/
Install required Node.js modules:
npm run reinstallDeployment of the Expense App API requires the AWS Command Line Interface (CLI) and AWS IAM Identity Center (formerly AWS Single Sign-On [SSO]).
Download and install AWS CLI version 2 following instructions from: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
NOTE: On Windows, the commands from this section can only be run from the Windows Command Prompt [cmd]. All other commands can be executed from a Windows Git Bash terminal.
You must first configure (one-time) AWS SSO using the AWS CLI.
aws configure ssoWhen prompted, enter the following information:
- SSO session name: dev
- SSO start URL: https://d-90676ba57e.awsapps.com/start
- SSO region: us-east-1
- SSO registration scopes: leave blank to accept default value of sso:account:access
Your web browser will open a new tab and you will be required to login to Google with your @consultwithcase.com email address and then press the Allow button to explicitly permit the authorize request. Close the web browser tab. Return to your command prompt and continue answering questions:
- Use keyboard to select Case Consulting Dev AWS account
- Use keyboard to select AdministratorAccess role
- CLI default client Region: us-east-1
- CLI default output format: json
- CLI profile name: default
If you have been given access to the company's AWS Prod account, run the aws configure sso command (one-time)
to configure a prod profile.
Choose the same values, except select Case Consulting Prod AWS account and enter prod as CLI profile name.
To explicitly obtain AWS credentials from AWS SSO, running aws sso login.
Your web browser should open a new tab, where you should be required to login to Google with your @consultwithcase.com
email address (unless you recently did so) and then press the Allow button to explicitly permit the authorize request.
To remove AWS credentials run aws sso logout. This will also clear any authorization.
Therefore, a subsequent login will launch the web browser again for a new authorization request.
The following environment variables are required to use Auth0 authentication:
- VITE_AUTH0_AUDIENCE
- VITE_AUTH0_DOMAIN
The following environment variables are required to support multiple environments:
- EXPRESS_PORT
- STAGE
The following environment variable is required to support deployments using ~/.aws/config to
configure credentials
for AWS SSO:
- AWS_SDK_LOAD_CONFIG (with a value of 1 [true])
The dotenv Node.js module picks up environment variables from a .env file in the project root directory.
The .env file in the S3 bucket in the company's AWS Dev account has up-to-date values to run locally.
Download this file to the project root directory:
npm run download:local:envTo download a specific environment's .env file,
where {Stage} is the name of the environment (e.g., local, dev, test, prod):
npm run download:{Stage}:envTo run locally (using pm2 configuration defined in services.yml):
npm run startTo stop running locally (using pm2):
npm run stopTo run locally (using pm2 configuration defined in services.yml, but on a different port):
EXPRESS_PORT=8081 npm run startTo run locally (using nodemon, with debug enabled):
npm run debugTo stop running locally (using nodemon), press CTRL-C in same window.
To run unit tests, first download the dev environment files:
npm run download:devTo run unit tests (with Jasmine):
npm run testTo run unit tests coverage (with Jasmine):
npm run test-coverageTo upgrade to the latest version of a specific Node.js module:
npm update --save <module-name>@latestTo upgrade to the latest version of a specific Node.js module, which is a development dependency only:
npm update --save-dev <module-name>@latestTo sync expense receipt names with S3 bucket file names:
npm run receiptSync:dev
npm run receiptSync:test
npm run receiptSync:prodYou can see all the current lambda function tests by running command:
npm run testLambdaLocal
To test a specific lambda function run the command:
npm run testLambdaLocal {LambdaOption}
Add a new test
- In test-local.js file in the Lambdas section add a new object key in the lambdas JSON object.
- For that new key create a JSON object with 2 key pairs: function and event.
- function should be set to the pathTo the file location of the Lambda function you want to test
- event should be set a String value with the value of the path location to the event file that you want to test against your Lambda function.
Example:
const lambdas = {
template: { function: pathTo('lambda-template/app.js'), event: 'lambda-template/event.json' }
};To run the template example the command would be:
npm run testLambdaLocal template
NOTE: When deleting a table and it is not recreated when deploying, you must change the table name in
CloudFormation.yaml, deploy, delete the new temporary table, change the table name back, and deploy again
NOTE: After first time deployment of S3 'Remove Deleted Expense Attachments' lifecycle rule, need to enable clean up expired object delete markers from S3 console.
In the S3 Console:
- Navigate to case-expense-app-attachment-{dev/test} or case-consulting-expense-app-attachment-{prod} bucket
- Click the Management tab
- Select the 'Remove Deleted Expense Attachments' lifecycle rule
- Click Edit
- Next
- Next
- Check the box for 'Clean up expired object delete markers'
- Next
- Save
To download dev .env and claudia.json and then deploy to the dev environment using Claudia.js
and SAM/CloudFormation:
npm run deploy:devTo download test .env and claudia.json and then deploy to the test environment using Claudia.js
and SAM/CloudFormation:
npm run deploy:testNOTE: Need to switch AWS credentials to AWS Prod account.
To download prod .env and claudia.json and then deploy to the prod environment using Claudia.js
and SAM/CloudFormation:
npm run deploy:prod-
Request certificates through AWS Certificate Manager
- App Certificate: sandbox-app.consultwithcase.com
- Api Certificate: sandbox-api.consultwithcase.com
-
Add CNAME records to Netlify for certificates
- Notice that consultwithcase.com will be appended to the name, so when copying from AWS, remove that before saving
-
Add sandbox to stage options
- Add to AllowedValues of CloudFormation parameters
- Stage: sandbox
- AppDomain: sandbox-app.consultwithcase.com
- Add to Stages constant cloudformation.js
- Add to AllowedValues of CloudFormation parameters
-
Create the support stack
- npm run deploy:cloudformation support sandbox
-
Update environment resource files
- Create and upload a new .env file
- Remove claudia.json file
-
Create network CloudFormation stack
- npm run deploy:cloudformation network sandbox
-
Create database CloudFormation stack
- npm run deploy:cloudformation database sandbox
-
Create the app CloudFormation stack
- Comment out all AWS::Serverless resources (functions and layers) as well as anything that depends on them (like log groups) from the template
- Upload the template to the CloudFormation console
- Use the ARNs from certificates made in Step 1 to fill in the parameters
-
Deploy the app CloudFormation stack
- Uncomment the resources from Step 8
- npm run deploy:cloudformation app sandbox
-
Create API Gateway
- npm run create:claudia:sandbox
-
Upload claudia.json file to S3
- aws s3 cp claudia.json s3://case-expense-app-resources-sandbox/claudia.json
-
Update API Gateway in console
- Change Endpoint Type to Regional
- Create a custom domain name and API mapping for the API Gateway
-
Add CNAME records to Netlify for for app and api
- Again, notice that consultwithcase.com will be appended to the name, so when copying from AWS, remove that before saving
-
Add callback URL to Auth0 settings
- Sign in to Auth0 account
- Add https://sandbox-app.consultwithcase.com/callback under Allowed Callback URLs and Allowed Web Origins settings
-
Add lamda role ARN to KMS employees-sensitive-key key policy
-
Create or import user records
- For a user to be able to login they need to have a record in the employees and employees-sensitive tables
If getting this error
Unable to upload artifact ./ referenced by CodeUri parameter of ChronosFunction resource. [Errno 2] No such file or directory: '/Users/austinlam/Documents/expense-app-case/expense-app-api/node_modules/.bin/babylon'
Run the following commands:
npm cache clean --force
rm -rf node_modules package-lock.json
npm run reinstallThis function was removed. If any references to it (or other training url scraping functionality) are found, they should be removed.
A nightly function that scrapes metadata from URLs provided in all employee expenses. Database entries will be made from the scraped URL data, the expense category, and the number of times a URL was used.
A nightly function that will create new budgets for recurring (yearly) expense types IF an employee overdrafted from the previous year on an employee's anniversary
A monthly function that updates durations for an employee. Durations that are updated are:
- Technology experiences that are currently being used by the employee
- Customer Organization experience that the employee is currently under
A nightly function that syncs data between the Portal and external applications. The Portal is the main/predominant source of data. Data will only be synced under specific scenarios:
- Data will be added to the Portal ONLY IF the field is empty on the Portal AND the external application's field is NOT empty
- Data will be added/modified on the external application under two scenarios:
- There is a data mismatch between the Portal's and the external application's field
- The data exists on the Portal's field and does NOT exist on the external application's field
External applications being synced with the Portal are:
- BambooHR
- ADP
Fields being synced between the Portal and external applications:
- First Name
- Middle Name
- Last Name
- Nickname
- Current Street
- Current City
- Current State
- Current ZIP
- Mobile Phone
- Home Phone
- Work Phone
- Work Phone Extension
- Date Of Birth
- Gender
- Ethnicity
- Disability
- Veteran Status
- Hire Date
AWS SDK V3:
https://docs.aws.amazon.com/sdk-for-javascript/
AWS CLI V2:
https://docs.aws.amazon.com/cli/index.html
AWS SSO:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html
AWS CloudFormation:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html
Axios:
https://github.com/axios/axios
Claudia.js
Express:
Metascraper:
Lodash:
Day.js: