# Upgrade Guide

## Project Zapp'd

The lambdas in the lambda-royalty-accounting repo will be ported over to
this repo, and in the process we will remove all traces of zappa and the
damage it has wrought.

### Getting started

To begin, create a directory with the new lambda's name in the `lambda/`
directory (side note, I'd like to remove the `lambda` directory and bring
the lambdas to the top level)

Copy over the following files from the lambda-royalty-accounting code:

- `.env.shadow` (remove `export` from env vars where present. remove unused values)
- `.flake8`
- `index.py` -rename-> `app.py` and update references
- `dev.py`
- `docker-compose.yml` if it exists
- `Makefile` (remove all "deploy" definitions)
- `README.md`
- `requirements-dev.txt`
- `requirements-to-freeze.txt` - remove zappa, and any unused deps
- `tests/`
- the module directory

Inside of the module directory, you may want to consolidate `constants.py`
into `config.py` .
You should also remove the sentry connector and set up sentry
in `app.py` like [in snapshot_adjustments](
https://github.com/theorchard/lambda-abacus/blob/master/lambda/snapshot_adjustments/app.py
)

Now to generate a `requirements.txt` file, run:
> make pip_lock_versions

### Setup docker

Create a Dockerfile like [here](https://github.com/theorchard/lambda-abacus/blob/master/lambda/snapshot_adjustments/Dockerfile)

Update the `Makefile` with commands to build and run the lambda locally
[example](https://github.com/theorchard/lambda-abacus/blob/master/lambda/snapshot_adjustments/Makefile#L53-L59)

### Deployment

Containerized lambdas need to be published to ECR to be deployed.
Your lambda's name will be the name of the directory it is in, with the
underscores converted to hyphens and prefixed by *lambda-abacus*. Example:
The lambda in the *snapshot_adjustments* directory will be deployed as
*lambda-abacus-snapshot-adjustments*.

The lambda will need to be defined in terraform [like here](https://github.com/theorchard/terraform-infra/blob/master/qa/lambda-abacus/main.tf#L30-L53)

### Additional Considerations

If tests contained `patch`ed version of owsrequest, please update the test
to use the `request_engine` fixture in place of patching. This allows you to
mock the results of the code's call to another service by adding the call
to expect and the response to deliver.
