# `set_carveouts` lambda

The `set_carveouts` lambda combines product specific carveouts from the income event with default ones (account / subaccount level) and sets product carveouts if they differ from the default ones. Set 'product.carveouts' field to the output event.



## 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
```

Update the `identity_uuid` to yours in `event.json` and the `ENVIRONMENT` to `qa` in the `.env`.

To get a recent event for local development, you can visit the [#qa-ccm-bulk-product-creation-alerts](https://sonymusic.enterprise.slack.com/archives/C09U6ML41E2) slack channel, which shows active sessions in QA with links to the step function. You will need to click on the step function in "Graph View", and then on the right click "Map Run". You can then select one of the Executions, and within that view, select SetCarveouts. 

You can copy the `set_carveouts` lambda input and drop it into the `event.json`. Remember to update the `identity_uuid` to yours.

_Note_: You may use the event.shadow.json event example, but there is a chance it is not up to date if there have been recent schema changes in the `common` dir.

## 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

# Start the lambda container
make docker_up

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

# End the lambda container
make docker_down
```
