# `generate_ingestion_failure_report` lambda

The `generate_ingestion_failure_report` lambda generates a re-upload XLSX spreadsheet containing only the products that failed during bulk ingestion. It downloads the original spreadsheet from S3, filters it to keep only the failed products (across all 7 sheets), uploads the filtered version back to S3, and updates the bulk session ingestion record with the file reference.



## Setup

### Install [`uv`](https://docs.astral.sh/uv/)

Choose your favourite or similar:

```shell
pip install uv
pipx install uv
brew install uv
```

### Permissions

Use [`awsume`](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f#5618a9119254428e9baeada414767e85):


```shell
awsume prod
```


### Install Packages

```shell
make uv_dev
```


### Copy and edit env and event.json shadows

```shell
cp event.shadow.json event.json
cp .env.shadow .env
```



## Local Development

```shell
# Install uv
brew install uv

# Install dependencies + create .venv (uv)
make uv_dev

# Run the function locally using event.json and print results
make dev

# Run formatting (ruff)
make fmt

# Run linting (ruff/mypy)
make lint

# Run unit tests (pytest)
make test_unit
```


## Local Development (Docker)

```shell
# Ensure the Docker daemon is running
docker ps

# `DD_TRACE_ENABLED=false`: Start the lambda container (with DD tracing disabled for local dev)
# `ENVIRONMENT=qa`: Enable ImpersonationM2MTokenManager to fetch the credential secret from qa/lambda-product-staging-generate-failure-report/...
ENVIRONMENT=qa DD_TRACE_ENABLED=false make docker_up

# Send event.json to the local lambda container
make docker_event

# End the lambda container
make docker_down
```
