Spaces:
Sleeping
Sleeping
Download lambda-deployment/lambda_function.py from mousom/caltrans-pt: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/mousom/caltrans-pt/resolve/main/lambda-deployment/lambda_function.py
- Command line
-
hf download hf://spaces/mousom/caltrans-pt/lambda-deployment/lambda_function.py
-
curl -L -o lambda_function.py https://huggingface.co/spaces/mousom/caltrans-pt/resolve/main/lambda-deployment/lambda_function.py
1.44 kB
| import json | |
| import sys | |
| import os | |
| # Add the current directory to the Python path so we can import main | |
| sys.path.append(os.path.dirname(__file__)) | |
| from mangum import Mangum | |
| from main import app | |
| # Create the Lambda handler using Mangum | |
| handler = Mangum(app, lifespan="off") | |
| def lambda_handler(event, context): | |
| """ | |
| AWS Lambda handler function for the Caltrans Payment Tracking API | |
| This function serves as the entry point for AWS Lambda and routes | |
| HTTP requests to the FastAPI application using Mangum adapter. | |
| Args: | |
| event: AWS Lambda event object containing the HTTP request | |
| context: AWS Lambda context object containing runtime information | |
| Returns: | |
| HTTP response formatted for AWS API Gateway | |
| """ | |
| try: | |
| # Use Mangum to handle the FastAPI app | |
| response = handler(event, context) | |
| return response | |
| except Exception as e: | |
| # Return error response if something goes wrong | |
| return { | |
| 'statusCode': 500, | |
| 'headers': { | |
| 'Content-Type': 'application/json', | |
| 'Access-Control-Allow-Origin': '*', | |
| 'Access-Control-Allow-Headers': 'Content-Type', | |
| 'Access-Control-Allow-Methods': 'OPTIONS,POST,GET' | |
| }, | |
| 'body': json.dumps({ | |
| 'error': 'Internal server error', | |
| 'message': str(e) | |
| }) | |
| } | |