Skip to content

Commit

Permalink
chore(#42): enable offline env vars with .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
namanaman committed Feb 16, 2024
1 parent 3ec6c4b commit 71d5e3f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ This project has been generated using the `aws-nodejs-typescript` template from
## Setup

1. Clone this repository
2. Create `.env` file in root directory, pasting in values from [Bitwarden secure note](https://vault.bitwarden.com/#/vault?collectionId=30a0c305-72f6-4e50-a403-b09a010f5467&itemId=65d29f31-d443-415d-b8b9-b10f017a41a5)
3. Run `source .env` in terminal to export into environment
4. Run `npm install` (on Node 18, as listed in `.nvmrc`) to install Node dependencies
5. Run `npx sls offline` to start the API locally
6. In another terminal, try calling API endpoints such as the example below. Note that this will actually add data to our live production database (Google Sheets). We hope to create a local and/or dev stage later.
2. Create `.env` file in root directory, pasting in values from [Bitwarden secure note](https://vault.bitwarden.com/#/vault?collectionId=30a0c305-72f6-4e50-a403-b09a010f5467&itemId=65d29f31-d443-415d-b8b9-b10f017a41a5). Note that these values are production keys that will allow for live testing. We hope to create a dev or local stage in the future.
3. Run `npm install` (on Node 18, as listed in `.nvmrc`) to install Node dependencies
4. Run `npx sls offline` to start the API locally
5. In another terminal, try calling API endpoints such as the example below. Note that this will actually add data to our live production database (Google Sheets).

```bash
curl -d '{"pageURL":"www.test.com","rating":true}' -H "Content-Type: application/json" http://localhost:3000/rating
Expand All @@ -23,10 +22,9 @@ Deployment is done locally to the AWS account `Innov-RES-Dev` and _not_ yet conn

1. Make code changes locally
2. Test code changes locally
3. Ensure that environment variables are set before deploying, as they currently override the ones set in AWS
4. Log into AWS console, and open "Command line and programmatic access" option under `Innov-RES-Dev` account
5. Follow instructions in modal to save AWS credentials to `~/.aws/credentials` file
6. Run `npx sls deploy --aws-profile {INSERT PROFILE NAME HERE}` to deploy this Serverless project to AWS
3. Log into AWS console, and open "Command line and programmatic access" option under `Innov-RES-Dev` account
4. Follow instructions in modal to save AWS credentials to `~/.aws/credentials` file
5. Run `npx sls deploy --aws-profile {INSERT PROFILE NAME HERE}` to deploy this Serverless project to AWS

## Installation/deployment instructions

Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"serverless": "3.38.0",
"serverless-esbuild": "1.51.0",
"serverless-offline": "12.0.4",
"serverless-offline-ssm": "6.2.0",
"ts-node": "10.9.2",
"tsconfig-paths": "3.15.0",
"typescript": "4.9.5"
Expand Down
11 changes: 10 additions & 1 deletion serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import summary from '@functions/summary';
const serverlessConfiguration: AWS = {
service: 'feedback-api',
frameworkVersion: '3',
plugins: ['serverless-esbuild', 'serverless-offline'],
plugins: [
'serverless-esbuild',
'serverless-offline-ssm',
'serverless-offline'
],
provider: {
name: 'aws',
stage: 'dev',
runtime: 'nodejs18.x',
timeout: 30,
deploymentBucket: {
Expand Down Expand Up @@ -57,6 +62,10 @@ const serverlessConfiguration: AWS = {
},
'serverless-offline': {
noPrependStageInUrl: true
},
'serverless-offline-ssm': {
// Values mocked by .env file
stages: ['dev']
}
}
};
Expand Down

0 comments on commit 71d5e3f

Please sign in to comment.