-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION=0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
|
||
|
||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Azure Functions in Python | ||
|
||
## Usage | ||
|
||
```shell | ||
mkdir azure_functions_basic | ||
cd azure_functions_basic | ||
|
||
# Create a new Azure Functions project | ||
func init --python --docker | ||
|
||
# Create virtual environment | ||
python -m venv .venv | ||
|
||
# Activate the virtual environment | ||
source .venv/bin/activate | ||
|
||
# Install the required packages | ||
pip install -r requirements.txt | ||
|
||
# Run the project locally | ||
func start --verbose | ||
``` | ||
|
||
## Deploy | ||
|
||
```shell | ||
# Deploy resources to Azure | ||
bash scripts/deploy_resources.sh | ||
|
||
# Deploy the Function App to Azure | ||
FUNCTION_APP_NAME="adhoc-azure-functions-..." | ||
func azure functionapp publish $FUNCTION_APP_NAME | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from os import getenv | ||
|
||
from fastapi import FastAPI | ||
|
||
app = FastAPI( | ||
docs_url="/", | ||
) | ||
|
||
|
||
@app.get("/info") | ||
def read_root(): | ||
return { | ||
"VERSION": getenv("VERSION", "0.0.0"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import azure.functions as func | ||
import datetime | ||
import json | ||
import logging | ||
from core import app as fastapi_app | ||
from dotenv import load_dotenv | ||
|
||
app = func.FunctionApp() | ||
load_dotenv() | ||
|
||
app = func.AsgiFunctionApp( | ||
app=fastapi_app, | ||
http_auth_level=func.AuthLevel.ANONYMOUS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"FUNCTIONS_WORKER_RUNTIME": "python", | ||
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing", | ||
"AzureWebJobsStorage": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
azure-functions==1.20.0 | ||
python-dotenv==1.0.1 | ||
fastapi==0.114.0 |
34 changes: 34 additions & 0 deletions
34
templates/azure_functions_basic/scripts/deploy_resources.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
# Variables | ||
LOCATION=japaneast | ||
RANDOM_SUFFIX=$(openssl rand -hex 4) | ||
RESOURCE_GROUP_NAME="rg-adhoc-azure-functions-$RANDOM_SUFFIX" | ||
STORAGE_NAME=stadhoc"$RANDOM_SUFFIX" | ||
FUNCTION_APP_NAME=adhoc-azure-functions-"$RANDOM_SUFFIX" | ||
|
||
# Create a resource group | ||
az group create \ | ||
--name "$RESOURCE_GROUP_NAME" \ | ||
--location "$LOCATION" | ||
|
||
# Create a storage account | ||
az storage account create \ | ||
--name "$STORAGE_NAME" \ | ||
--location "$LOCATION" \ | ||
--resource-group "$RESOURCE_GROUP_NAME" \ | ||
--sku Standard_LRS | ||
|
||
# Create a function app | ||
az functionapp create \ | ||
--resource-group "$RESOURCE_GROUP_NAME" \ | ||
--consumption-plan-location "$LOCATION" \ | ||
--runtime python \ | ||
--runtime-version 3.11 \ | ||
--functions-version 4 \ | ||
--name "$FUNCTION_APP_NAME" \ | ||
--os-type linux \ | ||
--storage-account "$STORAGE_NAME" | ||
|
||
# create json file containing the resource group name and storage account name | ||
echo "{\"RESOURCE_GROUP_NAME\": \"$RESOURCE_GROUP_NAME\", \"STORAGE_NAME\": \"$STORAGE_NAME\", \"FUNCTION_APP_NAME\": \"$FUNCTION_APP_NAME\"}" |