# Create Manifest Function

This Lambda function is responsible for creating and validating the training manifest for AWS Rekognition Custom Labels. It processes XML annotation files and their corresponding JPG images to create a properly formatted manifest file.

## Functionality

1. **Source Data Processing**
   - Scans the source S3 bucket for XML annotation files
   - Processes each XML file to extract bounding box annotations
   - Validates the corresponding JPG images exist

2. **Manifest Creation**
   - Converts XML annotations to AWS Rekognition format
   - Creates a JSONL manifest file with proper formatting
   - Uploads the manifest to the training bucket with correct content type

3. **Validation**
   - Verifies the manifest format meets AWS Rekognition requirements
   - Ensures all referenced images are accessible
   - Validates bounding box coordinates and annotations

## Environment Variables

- `SOURCE_BUCKET`: S3 bucket containing XML and JPG files
- `TRAINING_BUCKET`: S3 bucket where the manifest will be stored

## Input/Output

### Input
- No specific input required
- Function scans source bucket for XML files

### Output
```json
{
    "statusCode": 200,
    "body": {
        "message": "Manifest created successfully",
        "entry_count": <number of entries>,
        "manifest_file": "s3://<bucket>/manifest.jsonl"
    }
}
```

## Error Handling

The function handles various error cases:
- Missing environment variables
- No XML files found
- Invalid XML annotations
- Missing JPG images
- Manifest validation failures

## Dependencies

- boto3>=1.26.0 (AWS SDK for Python)

## Usage

The function is automatically triggered when:
1. New XML files are uploaded to the source bucket
2. Manually invoked to recreate the manifest

## Manifest Format

The manifest follows AWS Rekognition's JSONL format:
```json
{
    "source-ref": "s3://<bucket>/<image>.jpg",
    "annotations": [
        {
            "class_id": 0,
            "left": <x>,
            "top": <y>,
            "width": <width>,
            "height": <height>
        }
    ]
}
```

## Notes

- The manifest file is created with content type `application/x-amazon-s3-object-manifest-jsonl`
- Each manifest entry must reference a valid JPG image in the source bucket
- Bounding box coordinates must be normalized (0-1)

## Related Resources

- [AWS Rekognition Custom Labels Documentation](https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/what-is.html)
- [Manifest File Format](https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/md-manifest-files.html)
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) 