# slz_gdpr_email_downloader lambda
slz_gdpr_email_downloader lambda scan source bucket for available emails, create for each corresponding
content_status in content_status table, extract attached csv from email, validate it using json 
schema and store csv in destination(decompressed) bucket.


## Lambda Environment variables
To execute the slz_gdpr_email_downloader lambda the following environment variables must be configured:

| Variable                 | Description                        
|--------------------------|------------------------------------
| `ENVIRONMENT`            | Environment name (`prod`, `dev`)   
| `RDS_SECRETS_KEY`        | Path to SLZ DB secrets             
| `BUCKET_SOURCE`          | Source bucket to search for emails 
| `BUCKET_DESTINATION`     | Bucket to store extracted and validated csv                  
| `CONFIG_BUCKET`          | Bucket with validation schemas               
| `SENTRY_SECRET_KEY`      | Path to Sentry secrets             



## Lambda Input
```json
{
    "dsp": "appreciationengine",
    "extension": "json",
    "trace_id": "dcb130c3-8046-4640-a81d-71d9d01b9341",
    "subtype": null,
    "job_id": "appreciationengine-20210416-sme-request_to_forget-v1_26953_20210417T04.18.31",
    "uow_id": "appreciationengine-20210416-sme-request_to_forget-v1",
    "licensor": "sme",
    "optional_config": {
        "DSP_CONFIG_KEY": "dsp_config_ae_email.json"
    },
    "report_type": "request_to_forget",
    "version": "v1",
    "report_date": "2021-04-16"
}
```

## Lambda Output
In case of successful lambda execution the following output will be provided:
```json
{
    "meta": {
      "status": "OK",
      "results": {
        "08fbkert711umdnqpkthbjikbatvvlq6e2014b01": false,
        "08fbkert711umd4567thbjikbatvvlq6e2011234": true, 
          # key is context(email name from source S3 bucket which is a unique hash generated by AWS SES)
      }
    }
}
```

## Local testing

- Prepare CloudWatch event
- Put it into the `events/`
- Edit __main__.py to use added CW event(if you use IDE)
- Execute lambda:

```
    python slz_gdpr_email_downloader -e <environment> -p <event>.json
```
