from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler.api_gateway import ( APIGatewayHttpResolver, Response, content_types, ) from aws_lambda_powertools.event_handler.exceptions import ServiceError from aws_lambda_powertools.event_handler.openapi.models import ( HTTPBearer, Server, ) from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.utilities.typing import LambdaContext from routes import courses, enrollments, orders, users, webhooks tracer = Tracer() logger = Logger(__name__) app = APIGatewayHttpResolver(enable_validation=True) app.enable_swagger( servers=[Server(url='https://api.saladeaula.digital/v2')], title='EDUSEGĀ® Public API', path='/_swagger', compress=True, security_schemes={'bearerAuth': HTTPBearer()}, security=[{'bearerAuth': []}], persist_authorization=True, ) app.include_router(users.router, prefix='/users') app.include_router(enrollments.router, prefix='/enrollments') app.include_router(orders.router, prefix='/orders') app.include_router(courses.router, prefix='/courses') app.include_router(webhooks.router, prefix='/webhooks') @app.exception_handler(ServiceError) def exc_error(exc: ServiceError): return Response( body={ 'msg': exc.msg, 'err': type(exc).__name__, }, content_type=content_types.APPLICATION_JSON, status_code=exc.status_code, ) @logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP) @tracer.capture_lambda_handler def lambda_handler(event: dict, context: LambdaContext) -> dict: return app.resolve(event, context) # if __name__ == '__main__': # print( # app.get_openapi_json_schema(), # )