From 9050a8264c807790c7597799cb76f3046bf52225 Mon Sep 17 00:00:00 2001 From: Kara Johnson Date: Tue, 20 Jun 2023 12:49:43 -0500 Subject: [PATCH] Fast API configured and deployed --- FastAPIApp/__init__.py | 5 +++++ host.json | 6 +++++- requirements.txt | 3 ++- wrapper-function/__init__.py | 21 +++++++++++++++++++++ wrapper-function/function.json | 21 +++++++++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 FastAPIApp/__init__.py create mode 100644 wrapper-function/__init__.py create mode 100644 wrapper-function/function.json diff --git a/FastAPIApp/__init__.py b/FastAPIApp/__init__.py new file mode 100644 index 0000000..37364f0 --- /dev/null +++ b/FastAPIApp/__init__.py @@ -0,0 +1,5 @@ +import fastapi + +app = fastapi.FastAPI() + +# TODO: Add setup or configuration specifications for the application here diff --git a/host.json b/host.json index 87b3e39..555bf5e 100644 --- a/host.json +++ b/host.json @@ -10,7 +10,7 @@ }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[3.*, 4.0.0)" + "version": "[2.*, 4.0.0)" }, "concurrency": { "dynamicConcurrencyEnabled": false, @@ -18,6 +18,10 @@ }, "functionTimeout": "00:10:00", "extensions": { + "http": + { + "routePrefix": "" + }, "queues": { "maxPollingInterval": "00:00:30", "visibilityTimeout" : "00:00:30", diff --git a/requirements.txt b/requirements.txt index 76ea8eb..84e8910 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,9 +3,10 @@ # Manually managing azure-functions-worker may cause unexpected issues azure-cosmos -azure-functions==1.12.0 +azure-functions>=1.12.0 azure-identity azure-storage-blob==12.14.1 +fastapi requests bs4 xxhash \ No newline at end of file diff --git a/wrapper-function/__init__.py b/wrapper-function/__init__.py new file mode 100644 index 0000000..c440ec1 --- /dev/null +++ b/wrapper-function/__init__.py @@ -0,0 +1,21 @@ +import logging +import azure.functions as func +from FastAPIApp import app # Main API application + + +@app.get("/sample") +async def index(): + return { + "info": "Try /hello/K for parameterized route.", + } + + +@app.get("/hello/{name}") +async def get_name(name: str): + return { + "name": name, + } + + +async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse: + return await func.AsgiMiddleware(app).handle_async(req, context) diff --git a/wrapper-function/function.json b/wrapper-function/function.json new file mode 100644 index 0000000..60ae420 --- /dev/null +++ b/wrapper-function/function.json @@ -0,0 +1,21 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ], + "route": "{*route}" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + } + ] +}