Lambda Function: Promote Silver Layer Data
Purpose
Automatically promotes validated Silver layer data after successful ETL completion by:
- Finding the most recent completed run (with
_SUCCESSmarker) - Copying Parquet files to
current/prefix for stable Athena queries - Updating
_LATEST.jsonto point to the promoted run
Architecture
Step Functions → Glue Job (ETL) → Lambda (Promotion) → S3 (current/ + _LATEST.json)
Trigger
Invoked by Step Functions state machine after successful ETL job completion.
Input (from Step Functions)
{
"silver_bucket": "ohpen-silver",
"silver_prefix": "silver/mortgages/transactions",
"schema_version": "v1",
"run_key": "execution-name-from-step-functions",
"glue_job_run_id": "jr_...",
"execution_arn": "arn:aws:states:...",
"execution_start_time": "2026-01-29T12:00:00.000Z"
}
When run_key is set, the Lambda promotes that run only. glue_job_run_id and execution_arn are logged and written into _LATEST.json for traceability.
Output
{
"status": "success",
"run_id": "20260129T120000Z",
"promoted_at": "2026-01-29T12:05:00.000Z",
"output_prefix": "silver/mortgages/transactions/year=2024/month=01/schema_v=v1/run_id=20260129T120000Z",
"current_prefix": "silver/mortgages/transactions/year=2024/month=01/schema_v=v1/current",
"files_copied": 5,
"latest_json": "silver/mortgages/transactions/year=2024/month=01/schema_v=v1/_LATEST.json"
}
S3 Operations
- Discovery: Searches for
_SUCCESSmarkers insilver_prefix/**/schema_v={version}/run_id=*/_SUCCESS - Selection: Picks the most recently modified
_SUCCESSmarker - Copy: Copies all
.parquetfiles fromrun_id=*/tocurrent/ - Metadata: Updates
_LATEST.jsonwith promotion metadata
Error Handling
- Returns error status if no completed runs found
- Returns error status if no Parquet files found
- Step Functions will catch errors and route to
HandleFailurestate
Deployment
Deployed automatically via Terraform:
- Function code packaged as ZIP from
lambda/promote_silver/directory - IAM role and policies created automatically
- CloudWatch Log Group created automatically
Testing
Test locally with:
python -m pytest tests/test_lambda_promote.py
Test in AWS:
aws lambda invoke \
--function-name ohpen-promote-silver \
--payload '{"silver_bucket":"ohpen-silver","silver_prefix":"silver/mortgages/transactions","schema_version":"v1"}' \
response.json