# Validate DDEX lambda

This lambda is used for validating a context (parsed_ddex.json) against a set of validation rules that are relevant for the ingestion source of the DDEX (Sony, AWAL etc).

## Are there any additional environment variables used?

This lambda requires three new additional environment variables to be set in order to save validation results to RDS:

- `RDS_HOST` - Host of RDS DB
- `RDS_DB_NAME` - Name of DB to connect
- `RDS_USER` - Username used in the DB connection

## What is a validation rule?

A validation rule is a function that executes on a field in the context passed to this lambda. A rule could be responsible for checking if there are tracks on the context or whether the context includes a Product name etc. All validation rule functions have one argument which is the context that we wish to validate against. A rule should always return a `RuleResult` which should be defined with a `rule_id` and a `response` of either `SUCCESS`, `WARNING` or `REJECT`. A helpful `message` field should also be defined for rules which are `WARNING` or `REJECT`.

These `RuleResult` outputs will then be written to an RDS DB defined by `RDS_HOST` and `RDS_DB_NAME` into a table named `CATALOG_INGESTION_VALIDATION_RESULT`.

## Great, how do I add a new validation rule?

Inside `rule.py` is where the validation rule functions live. You can pretty much copy the format of another rule and modify it to suit your needs. 

## How do I modify the rules that are executed for a specific ingestion source, such as Sony or AWAL?

Inside `rule.py` there is a dictionary property named: `RULES_PER_INGESTION_SOURCE_ID` which includes a key of the ingestion source id and a value of the validation rules that you wish to run against this ingestion source. Currently we are defaulting the 'ingestion_source_id' to 1 and assuming that an id of 1 equals a Sony ingestion.
