# lambda-documents

### Building the lambda
* copy the .npmrc.shadow > .npmrc and .env.shadow > .env
* populate .env with GITHUB_TOKEN
* populate the .npmrc file (these should be the same tokens used for the frontend)
* If using an m1 mac you will most likely need to make the following changes:
    * Add `platform: linux/amd64` to the docker-compose.yaml under the function definition
    * Go to the docker app settings > features in development and turn on `Use Rosetta for x86/amd64 emulation on Apple Silicon`
* If `ENV=qa`, you may need to update the `getToken` and `configureSentry` function
    * ```export async function getToken() { return null; };```
    * ```export async function configureSentry() { return; };```

### Running the lambda locally:
```
export GITHUB_NPM_TOKEN={PUT YOUR TOKEN HERE} // go ahead and do it if you haven’t already.

yarn install
docker-compose up --build -d function
yarn start
```

### To send a request:
```
curl -v "http://localhost:{PORT}/2015-03-31/functions/function/invocations" -H 'Content-type: application/json'  -d @scratch/payload.json
```
(the port should be defined in the docker-compose.yaml)

### Unit tests

```
yarn test
```

### Unit tests and linting in docker

```
docker-compose up -d --build lint-and-test
```


### integration tests
* populate .env with GITHUB_TOKEN
* run these commands one by one

```
yarn install
docker-compose up -d
yarn test:integration
docker-compose down
```

## GraphQL Codegen

When adding or updating mutations to a lambda, you can run `yarn generate` in the lambda's directory to automatically create the types based on the GraphQL document specified. The types will be output to `src/graphql/generated.ts` which should not be edited manually.


### Docker security scan

To run the scan locally, awsume the prod AWS and use the following command:

```sh
make scan_docker_image function_name=<function_name>
```

e.g.

```sh
make scan_docker_image function_name=calculate-payments
```
This will build the docker image for the lambda and run the scan. 
