# lambda-metadata-generator
Metadata generators for store delivery.

## Documentation 
Page describing use within the neighbouring rights [delivery workflow](https://www.notion.so/Performance-Delivery-Workflow-54f9f919a5bf44d797f2e91a52e55e04)

[Runbook](https://www.notion.so/lambda-metadata-generator-66dfe8e2b16f4855a7d3d2f1258f75f7)

## Requirements
* Install [yarn](https://classic.yarnpkg.com/lang/en/docs/install/)


## Running

### .env

Copy `.env.shadow` to `.env`

For dev aws we use `NR_DELIVERY_BUCKET='test-orcd-bucket'` bucket. 

### Install dependencies

```
yarn 
```


### Running the handler directly

```
yarn dev:local:run

```
This runs `scripts/local-run.ts` which calls the handler() with a event object as the lambda expects. The output is printed on the console.
To run it for a different storeId or event data, you can edit the `local-run.ts` or `src/__fixtures__/event` and run it.



## Linting and Testing
We are running the lint and test tasks directly on the host, local environment or Jenkins.

```sh
yarn
yarn test
```
## Committing Changes
Please ensure you run `yarn format` before committing to ensure `prettier` gets run.

## Building

Building the lambda depends on 2 build arguments needed to install JS and TS packages.

```
PACKAGECLOUD_USER (this is a user not a token)
GITHUB_TOKEN
```

The `PACKAGECLOUD_TOKEN` is needed for getting our older JS packages from our PackageCloud.
The `GITHUB_TOKEN` is needed for getting our newer TS packages from the Github monorepo.

These secrets are boud in the Jenkins job as environment variables and then saved to a temp file in the workspace. The build command would be as follows. The Jenkins job will use the Docker Build and Publish plugin to build and push the image to ECR. It needs to be instructed to use BuildKit and the location of these secrets. 

## Docker

To run the function in Docker run
```
awsume prod
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 086679231553.dkr.ecr.us-east-1.amazonaws.com
docker compose up --build -d function
``

To run lint and test in Docker run
```
awsume prod
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 086679231553.dkr.ecr.us-east-1.amazonaws.com
docker compose up --build -d lint-and-test
``