Skip to content

Instantly share code, notes, and snippets.

@rajavijaysingh
Forked from Cox65/fastapi_app.py
Created September 10, 2024 12:51
Show Gist options
  • Select an option

  • Save rajavijaysingh/ac5caede04c79ba7c504a16574bf7f8d to your computer and use it in GitHub Desktop.

Select an option

Save rajavijaysingh/ac5caede04c79ba7c504a16574bf7f8d to your computer and use it in GitHub Desktop.

Revisions

  1. @Cox65 Cox65 revised this gist Dec 26, 2022. 1 changed file with 30 additions and 0 deletions.
    30 changes: 30 additions & 0 deletions serverless.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    org: cox65
    app: fastapi-aws-starter-kit
    service: fastapi-aws-starter-kit
    package:
    individually: true
    provider:
    name: aws
    runtime: python3.9
    region: eu-west-1
    httpApi:
    cors: true
    timeout: 10
    memorySize: 128
    plugins:
    - serverless-python-requirements
    - serverless-offline
    functions:
    app:
    package:
    patterns:
    - "fastapi_aws_starter_kit/**"
    handler: fastapi_aws_starter_kit.handler.handler
    events:
    - http:
    method: any
    path: /{proxy+}
    cors: true
    custom:
    pythonRequirements:
    dockerizePip: true
  2. @Cox65 Cox65 revised this gist Dec 26, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions web_server.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    import os
    import uvicorn

    if __name__ == "__main__":
    uvicorn.run(
    "fastapi_app:app",
  3. @Cox65 Cox65 revised this gist Dec 26, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions handler.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    from mangum import Mangum
    from fastapi_aws_starter_kit.fastapi_app import app

    handler = Mangum(app=app)
  4. @Cox65 Cox65 revised this gist Dec 18, 2022. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions web_server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    import os
    import uvicorn
    if __name__ == "__main__":
    uvicorn.run(
    "fastapi_app:app",
    host="127.0.0.1",
    port=5000,
    reload=True,
    )
  5. @Cox65 Cox65 revised this gist Dec 18, 2022. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions fastapi_app.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,7 @@
    from fastapi import FastAPI
    from starlette.middleware.cors import CORSMiddleware

    # Declare the application
    app = FastAPI(title="Sample FastAPI app", debug=False, version="1.0.0")


    app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
  6. @Cox65 Cox65 revised this gist Dec 18, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion fastapi_app.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    from fastapi import FastAPI
    from starlette.middleware.cors import CORSMiddleware
    from fastapi_aws_starter_kit.routers.health_check_api import router as hc_router

    # Declare the application
    app = FastAPI(title="Sample FastAPI app", debug=False, version="1.0.0")
  7. @Cox65 Cox65 revised this gist Dec 18, 2022. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions fastapi_app.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,9 @@
    from fastapi import FastAPI
    from starlette.middleware.cors import CORSMiddleware
    from fastapi_aws_starter_kit.routers.health_check_api import router as hc_router
    from fastapi_aws_starter_kit.config import PROJECT_NAME, API_VERSION

    # Declare the application
    app = FastAPI(title=PROJECT_NAME, debug=False, version=API_VERSION)
    app = FastAPI(title="Sample FastAPI app", debug=False, version="1.0.0")


    app.add_middleware(
  8. @Cox65 Cox65 created this gist Dec 18, 2022.
    22 changes: 22 additions & 0 deletions fastapi_app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    from fastapi import FastAPI
    from starlette.middleware.cors import CORSMiddleware
    from fastapi_aws_starter_kit.routers.health_check_api import router as hc_router
    from fastapi_aws_starter_kit.config import PROJECT_NAME, API_VERSION

    # Declare the application
    app = FastAPI(title=PROJECT_NAME, debug=False, version=API_VERSION)


    app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
    )

    @app.get(
    path="/health", description="Health check"
    )
    def health_check():
    return {"status": "OK"}