- I created the file
app_basic.pywhich houses code for a home page and a hello page. Once you enterpython app_basic.pyin the terminal, and click the provided link, you are redirected to the home page. The home page returns the response "Hello from my Flask API Endpoint Server", and the hello page returns the message of 'Hello in capital letters. One can get to the hello page by enteringhello?name=write_a_name_here&lastname=write_a_last_name_here. To test this, I write my first name after "name=" and my last name after "lastname=", as seen in the screenshot in theScreenshotsfolder. - In the
app_flasgger.pyfile, I included the hello page and response in the code.
- The first step in the Azure API deployment is to download, install Azure CLI, and connect your Google Cloud Shell to your Azure account.
- In your Google Cloud Shell terminal type the command
curl -sL https://aka InstallAzureCLIDeb | sudo bashto install Azure CLI - To test the installaation type
azinto the terminal and hit enter - After that login
az login --use-device-code- a link will appear and copy the authentication code it provides, click the link, provide the code and sign into your Azure account.
- In the terminal, install the Azure Core Tools package
sudo apt-get install azure- functions-core-tools-4 - Ensure you are in the right directly, if not utilize the command
cdto go into the right one, and run the commandfunc init LocalFunctionProj --python -m V2
- go into the project folder that was created by the previous command, to achieve this utilize this command
cd LocalFunctionProj.
- In the folder, there is a
function_app.pyfile that was created, replace the contents of the file with this code:
import azure.functions as func
app = func.FunctionApp()
@app.function_name(name="HttpExample")
@app.route(route="hello")
def test_function(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse("HttpExample function processed a request!")
- Open the file
local.settings.jsonand ensure that next toAzureWebJobsFeatureFlagshas the value ofEnableWorkerIndexingand update theAzureWebJobsStorageto:"AzureWebJobsStorage": "UseDevelopmentStorage=true" - Run the function locally by
func start - Create Azure resouces for your function to deploy the application:
- Create a resource group:
az group create --name <name of your resource group> --location <REGION>. Use this link to fnd your region. For instance, if you are in the Eastern part of the United States, inputeastus. - Create a storage account:
az storage account create --name <STORAGE_NAME> --location <REGION> --resource-group <resource group name> --sku Standard_LRS - Create the function app in Azure:
az functionapp create --resource-group <resource group name> --consumption-plan-location westeurope --runtime python --runtime-version 3.9 --functions-version 4 --name <APP_NAME> --os-type linux --storage-account <STORAGE_NAME>
- To deploy the function project to azure
func azure functionapp publish <APP_NAME>
- The
app_flasgger.pyfile details the code utilizd. - To open swagger, in the terminal run
python app_flasgger.py, then click the URL, and afercloudshell.dev/addapidocs, as you can see in the screenshot in the screenshots folder. Click theGETbutton and the parameters, response code and descriptions will appear (also can be seen in the screenshots in the screenshots folder).
- The first issue I encountered was running the
func init LocalFunctionProj --python -m V2command. I followed the tutorial but i did not realize in the terminal, I was not in any directory. When I was up to the "create and acticate a virtual environment" section of the tutorial I followed it and it led me to using .venv, I then ran thefunc initcommand like that and it created all my files into my root directory. Then i had to use the commandmv <file name> flask_6_api_managementto retrieve every file and move it into the rigt directory. I then deleted all the files I moved to ensure no great mistakes were made due to the mass movement of files or if something had not moved properly. After that, I went into the right directory by utilizing the commandcdand then ran thefunc initagain, and all the files were produced in the right place. - Everything else worked smoothly, except for when I reached deployment. I successfully recieved all the comments in the terminal that my app sucessfully deployed, however when I clicked the link from the terminal, this came up:
I then went to the Azure website and went into App Servicesclicked on my the app name to check if everything was correct and running properly. I clicked the URL link provided and this appeared:
After that I scrolled down to the Functionsand clickedHTTPExamplewhich brought me to this:
I then clicked Get URL function, copied the default(functionkey)url and pasted it to a new tab and it worked!

