API Endpoints

The Amtrak Ingestion service exposes HTTP endpoints for health checks and manual triggering of pipeline operations.

HTTP Endpoints

Health Check

GTFS Update

Amtraker Update

Data Collation

Scheduled Functions

The following functions are triggered automatically by AWS EventBridge:

Update GTFS Cache

  • Schedule: Daily at 2:00 AM UTC

  • Function: update_gtfs_cache

  • Description: Checks and updates GTFS bundles from all enabled providers

Consume Amtraker API

  • Schedule: Every 5 minutes (rate(5 minutes))

  • Function: consume_amtraker_api

  • Description: Fetches train data, generates events, uploads to S3

Collate Previous Day

  • Schedule: Daily at 3:00 AM UTC

  • Function: collate_previous_day

  • Description: Collates all events from the previous day into CSV files

Cron Expression Reference

The scheduled functions use AWS cron expressions:

# Daily at 2:00 AM UTC
cron(0 2 * * ? *)

# Every 5 minutes
rate(5 minutes)

# Daily at 3:00 AM UTC
cron(0 3 * * ? *)

Error Responses

All endpoints may return the following error responses:

{
  "Code": "InternalServerError",
  "Message": "An internal server error occurred"
}

Status Codes:

  • 500 Internal Server Error - Unexpected error during processing

Usage Examples

Using curl

Health check:

curl https://your-api-gateway-url.amazonaws.com/api/

Trigger GTFS update:

curl -X POST https://your-api-gateway-url.amazonaws.com/api/gtfs/update

Trigger Amtraker update:

curl -X POST https://your-api-gateway-url.amazonaws.com/api/amtraker/update

Collate specific date:

curl -X POST "https://your-api-gateway-url.amazonaws.com/api/amtraker/collate?year=2025&month=11&day=15"

Using Python

import requests

BASE_URL = "https://your-api-gateway-url.amazonaws.com/api"

# Health check
response = requests.get(f"{BASE_URL}/")
print(response.json())

# Trigger GTFS update
response = requests.post(f"{BASE_URL}/gtfs/update")
print(response.json())

# Collate specific date
params = {"year": "2025", "month": "11", "day": "15"}
response = requests.post(f"{BASE_URL}/amtraker/collate", params=params)
print(response.json())