# Check Training Status

This Lambda function monitors the training status of Rekognition Custom Labels models and updates their status in Supabase. It's designed to be run periodically to track the progression of model training and to update database records when training completes.

## Functionality

The function performs the following operations:

1. Checks for models in `TRAINING` status in Supabase database
2. Verifies the training status directly from AWS Rekognition 
3. Updates Supabase records when training completes (successful or failed)
4. Returns a flag indicating whether all training is complete (for Step Functions workflows)

## Environment Variables

- `PROJECT_ARN`: ARN of the Rekognition Custom Labels project (will be fixed if format is incorrect)

## Required Project ID

All Rekognition operations require the correct project ID: `1725357683732`. The function includes logic to fix ARNs with incorrect project IDs.

## AWS Resources

The function requires:
- Permission to access AWS Rekognition
- Permission to access SSM Parameter Store
- The following SSM parameters:
  - `/supabase/url`: Supabase URL
  - `/supabase/anon`: Supabase anonymous key
  - `/datafy-rekognition-stack/project-name`: (Optional) Project name parameter

## Database Integration

The function integrates with Supabase to:
- Query model versions in `TRAINING` status
- Update model records with:
  - Current status
  - Status messages
  - Evaluation metrics (when training completes)
  - F1 score and quality criteria assessment

## Usage in Step Functions

When used in Step Functions workflows, the function returns a `training_complete` flag that can be used to determine if the workflow should proceed to the next step or wait for training to complete.

## Error Handling

The function includes robust error handling for various scenarios:
- Missing project ARN
- Incorrect ARN formats
- Supabase connection failures
- AWS API errors

## Troubleshooting

Common issues:
- If no project ARN is available, the function attempts to construct one using SSM parameters
- If no project is found by name, the function lists all available projects
- Logs include detailed information about project ARNs and model training status for debugging 