# Deindex product metadata Lambda

## What does this lambda do?

Given a dict with a "product_id" key, it will remove the product document from
the configured elasticsearch index, if the document exists.

## Usage

### Install

To install a development environment using `python 3.9`, you can run:

```sh
make pip_dev
```

### Requirements

- python3.11

Direct dependencies are listed in `requirements-to-freeze.txt` and locked with
their own dependencies in `requirements.txt`. `requirements.txt` is imported into
`requirements-test.txt` and testing dependencies are listed. To bump versions
of dependencies, update the version in `requirements-to-freeze.txt` and run
the command below to regenerate `requirements.txt`.

```sh
make pip_lock_versions
````

### Development

```sh
# Run the function locally using a test event and print results
make dev

# Run linting
make lint

# Run tests
make test

# Build the docker image, launch it, and run linting and tests against it
make docker_test

# Rebuild your local env from scratch
make clean dev
```

## Docker Stack

The docker stack offers an environment like the one on AWS for developing against.

```sh
# Bring the function up in a docker-compose stack. The container will mount
# src dir so it will update immediately as you develop.
make docker_up

# Send a mock event to the function
make docker_event

# Bring the stack down
make docker_down
```

> Note that this requires docker to be running locally and for you to grant docker
> permission to access your local directory.

## Datadog Configuration

In order to get traces and metrics (in addition to logs) from the [Datadog Lambda Library](https://docs.datadoghq.com/serverless/installation/python/?tab=containerimage), you'll need to have the following environment variables:

- DD_ENV (dev, qa, or prod)
- DD_SERVICE (the name of your service)
- DD_API_KEY_SECRET_ARN or DD_API_KEY (depending on how you are accessing the api key from secrets manager)
- DD_TRACE_ENABLED (set to true)

These can be set via terraform, for example [here](https://github.com/theorchard/terraform-infra/blob/master/qa/lambda-sound-recordings/lambda_sr_add_version.tf#L84-L91).
