# File Upload Complete

## Requirements

- Python 3.13
- [uv](https://docs.astral.sh/uv/) - Fast Python package manager
- Docker (for containerized testing and deployment)

## Overview

The lambda is called when the file to s3 is uploaded. 
After that the lambda sends a request to ows-royalties to complete the file upload. 

## Running

### Set up the environment
Copy the `.env.shadow` to a local `.env`:
```shell
cp .env.shadow .env
```

Install `uv` if you haven't already:
```shell
curl -LsSf https://astral.sh/uv/install.sh | sh
```

#### AWS Creds
Generate your AWS credentials using [awsume](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f?pvs=4#f11f08d09f16493a8a3e9dbf38d87164): `awsume prod`.

Get your `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN` by running `awsume prod -s`.

Copy the values into your `.env` and/or export them in your CLI.

Example export:
```shell
export AWS_ACCESS_KEY_ID=<secret>
export AWS_SECRET_ACCESS_KEY=<secret>
export AWS_SESSION_TOKEN=<secret>
```

#### Log into ECR:
```shell
# After generating aws creds
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 437795906767.dkr.ecr.us-east-1.amazonaws.com
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 086679231553.dkr.ecr.us-east-1.amazonaws.com
```

### Start local lambda
The lambda function can be run locally as a python function or as a container.

As a python function:
```shell
make run
```

As a container:
```shell
make docker_local_up
```

Note: This brings up the local code, if you want to pull and run the most recently deployed image run `make start_ows`, it may take a while either way 

### Execute Function

Use the HTTP client of your choice. The empty request body or None is passed into the function.

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

## Deployment

There is one shared [jenkins pipeline](https://pipeline.theorchard.io/job/lambda-abacus-pipeline/) for all abacus lambdas.
A webhook will trigger the deploy for the appropriate sub-directory in this repo.

## Integration testing

OWS services can be added to the `docker-compose.yml` file in order to test integrations.
