Spaces:
Sleeping
Download lambda-deployment/README.md from mousom/caltrans-pt: direct link, hf CLI and curl.
- Browser
- Download file 4.76 kB
-
https://huggingface.co/spaces/mousom/caltrans-pt/resolve/main/lambda-deployment/README.md
- Command line
-
hf download hf://spaces/mousom/caltrans-pt/lambda-deployment/README.md
-
curl -L -o README.md https://huggingface.co/spaces/mousom/caltrans-pt/resolve/main/lambda-deployment/README.md
A newer version of the Gradio SDK is available: 6.32.0
Caltrans Payment Tracking API - Lambda Deployment
This folder contains everything needed to deploy the Caltrans Payment Tracking API to AWS Lambda using AWS SAM (Serverless Application Model).
Files Overview
main.py- The FastAPI application (copied from parent directory)lambda_function.py- Lambda handler that wraps the FastAPI app using Mangumrequirements.txt- Python dependencies for Lambdatemplate.yaml- SAM template defining AWS resourcessamconfig.toml- SAM configuration filedeploy.sh- Deployment scriptREADME.md- This documentation
Prerequisites
AWS CLI - Install and configure with your AWS credentials
aws configureSAM CLI - Install the Serverless Application Model CLI
# macOS with Homebrew brew install aws-sam-cli # Or download from AWS documentation: # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.htmlAWS Account - Ensure you have appropriate permissions to create:
- Lambda functions
- API Gateway
- IAM roles
- CloudFormation stacks
Deployment Steps
Option 1: Quick Deployment (Recommended)
Make the deployment script executable:
chmod +x deploy.shRun the deployment script:
./deploy.shFollow the guided deployment prompts to configure:
- Stack name (default:
caltrans-payment-tracking-api) - AWS region (default:
us-west-1) - Other deployment parameters
- Stack name (default:
Option 2: Manual Deployment
Build the SAM application:
sam buildDeploy with guided setup:
sam deploy --guidedFor subsequent deployments (after initial setup):
sam deploy
API Endpoints
Once deployed, your API will be available at the provided API Gateway URL with these endpoints:
Core Endpoints
GET /- API information and available endpointsGET /health- Health check endpoint
Contract Payment Endpoints
GET /contracts/{contract_number}/payments- Complete payment history for a contractGET /contracts/{contract_number}/payments/monthly/{month}- Detailed monthly payments with CAS145 estimates
Example Usage
# Get API information
curl https://your-api-url.execute-api.us-west-1.amazonaws.com/prod/
# Get contract payment history
curl https://your-api-url.execute-api.us-west-1.amazonaws.com/prod/contracts/033F0704/payments
# Get detailed monthly payments for December 2024
curl https://your-api-url.execute-api.us-west-1.amazonaws.com/prod/contracts/033F0704/payments/monthly/2024-12
Configuration
Lambda Function Settings
- Runtime: Python 3.10
- Memory: 512 MB
- Timeout: 30 seconds
- Architecture: x86_64
API Gateway Settings
- CORS: Enabled for all origins
- Binary Media Types: Supported
- Stage: prod
Monitoring and Logs
- CloudWatch Logs: Lambda function logs are automatically sent to CloudWatch
- CloudWatch Metrics: Standard Lambda and API Gateway metrics are available
- X-Ray Tracing: Can be enabled for detailed performance monitoring
Cost Considerations
- Lambda: Pay per request and compute time
- API Gateway: Pay per API call
- CloudWatch: Standard logging and monitoring costs
Estimated cost for moderate usage (1000 requests/month): ~$1-2/month
Troubleshooting
Common Issues
- Import Errors: Ensure all dependencies are in
requirements.txt - Timeout Issues: Increase Lambda timeout in
template.yamlif needed - Memory Issues: Increase Lambda memory allocation for large responses
- CORS Issues: API Gateway CORS is pre-configured
Debugging
Check CloudWatch Logs:
sam logs -n CaltransPaymentTrackingAPI --stack-name caltrans-payment-tracking-api --tailLocal testing:
sam local start-apiInvoke function locally:
sam local invoke CaltransPaymentTrackingAPI
Updating the Application
- Make changes to
main.pyor other files - Run deployment again:
Or:./deploy.shsam build && sam deploy
Cleanup
To remove all AWS resources:
sam delete --stack-name caltrans-payment-tracking-api
Security Notes
- API is publicly accessible by default
- Consider adding API key authentication for production use
- All external HTTP requests are made from Lambda (ensure appropriate security groups if using VPC)
- No sensitive data is stored in the Lambda function
Support
For issues or questions about the API functionality, refer to the main application documentation or contact the development team.