# sr-delivery-meta

The purpose of this function is to pull a compiled sound recording version from S3, transform that data into [DDEX that meta understands](https://drive.google.com/file/d/1U1FGwgjchbkWa4smV6NNARMdSFZV8NDP/view?usp=sharing), and send it to meta.

## Required Additional Setup

1. Move environment file to setup `SENTRY_DSN` and `ID_RSA`.
  * `$ cp .env.shadow .env`

2. Copy private key into `.env`, escaping newlines that docker-compose won't handle properly
  * `$ echo ID_RSA=\""$(cat localdev/local_id_rsa | sed 's/$/\\\\n/g' | tr -d '\n')"\" >> .env`

:warning: If you experience errors about mounting the public key volume, try removing the shared volume the SFTP server uses.
* `$ rm -R ./localdev/share/`

## Notes

### Compiling Sound Recording Versions

See `./tests/sample_event.json` for an existing compiled sound recording version in dev **or** generate a compiled sound recording data to test with, use the sibling lambda function `sr-add-version` which writes JSON data to S3. Use the sound recording ID and version as input to this function.

### AWS S3

* Using the default `docker-compose.yaml` setup, credentials will be copied into the function container from `~/.aws/credentials` on your host machine and the environment variable `AWS_PROFILE=dev` will be set
* Sound recording versions by default are saved to `arn:aws:s3:::test-orcd-bucket/sound_recording_versions/`

### SFTP Server Local

By default, starting the `function` service via `docker-compose` will bring up an SFTP container service named `fake-book`. Single sound recording batches of XML and optionally audio assets will be uploaded there when running the lambda function locally.

To access SFTP server from your **host** machine via any SFTP client, see the parameters below.

| Parameter | Value |
| --- | --- |
| hostname | localhost |
| port | 2223 |
| username | orchard |
| SSH Private Key | ./localdev/local_id_rsa |
* Values are set in `docker-compose.yaml`
* Function container is automatically configured to connect within the docker network using private key in `.env`

### Optional Dev Sentry DSN

If you have a dev Sentry DSN to use (using either a catch-all DSN or by setting up a dev DSN for this lambda), you can:

* Fill in the DSN in `.env`
* The SENTRY_DSN env var in `docker-compose.yaml` will then pick this up

If you don't fill out the environment variable, docker-compose will warn you, but it is not required.
