# insights-search

Lambdas for orchestrating the flow of releases data from Art Relations into the Product ES index via Kafka.

# TODO: document the service

## Requirements

-   Install [docker](https://docs.docker.com/get-docker/)
-   Make sure docker-compose is version 2.18.1 or higher

## Building

Building the lambda depends on 1 build argument needed to install JS and TS packages.

```
GITHUB_TOKEN
```

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

The secrets are found 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.

### Deploying to Dev

If you want to build the image locally and push it to the AWS Dev ECR.

Login to an AWS dev session [using awsume](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f?pvs=4#f11f08d09f16493a8a3e9dbf38d87164).

Then run the dev:deploy script to build an image and send it to ECR.

```sh
yarn dev:deploy
```

## Running

### .env

You need the secret mentioned above if you want to build, run or test the containerized lambda locally. Copy `.env.shadow` to `.env`

### Start Container

```
$ docker-compose up --build -d function
```

### Execute Function

Use the HTTP client of your choice. The body of the request is the `event` passed into the function.

```sh
curl --request POST \
  --url http://localhost:9000/2015-03-31/functions/function/invocations \
  --header 'Content-Type: application/json' \
  --data '{}'
```

## Linting and Testing

Running the lint and test tasks directly on the host, local environement or Jenkins. For local testing make sure you run `yarn` and install the project locally.

```sh
yarn run prettier --write .
```

```sh
yarn test
```
