Skip to content

Instantly share code, notes, and snippets.

@thoughtful-solutions
Last active August 8, 2024 15:57
Show Gist options
  • Save thoughtful-solutions/7106918bc009a781a9cea90613cb4b6b to your computer and use it in GitHub Desktop.
Save thoughtful-solutions/7106918bc009a781a9cea90613cb4b6b to your computer and use it in GitHub Desktop.
Azure FAAS and COSMOSDB

Create a function for cosmosdb

Authenticate to Azure

az login

az account show

az account list

Create a Resources

It is crucial that resources can be shared and managed together

Create a Resource Group

az group create --name selectid000rg --location "ukwest"

List Resource Groups

This lists the resources by name, type, resource group and location

az resource list --query "[].{name:name, type:type, resourceGroup:resourceGroup, location:location}"

and you can limit these to see what is in a resource group with

az resource list --query "[].{name:name, type:type}"  --resource-group selectid000rg

Create a Storage Resources

Create a Storage Account

az storage account create --name faasstorage000 --location ukwest --sku Standard_LRS --resource-group selectid000rg

List Storage accounts

az storage account list --query "[].name" --resource-group selectid000rg

Create a Cosmos DB

The Cosmos DB needs creating associated with a resource group

Create a DB

 az cosmosdb create --name selectiddb --resource-group selectid000rg 

List the CosmosDB

az cosmosdb list --query "[].{name:name, endpoint:documentEndpoint}"

List keys for the CosmosDB

az cosmosdb keys list --name selectiddb --resource-group selectid000rg

Deploy a python FaaS

Create a python FaaS

az functionapp create --name auditserver --storage-account faasstorage000 --resource-group selectid000rg --runtime python --functions-version 4 --os-type linux --consumption-plan-location ukwest

Show the python FaaS

az functionapp list --query "[].{name:name, type:type, resourceGroup:resourceGroup, location:location, defaultHostName:defaultHostName,kind:kind}"

Publish python to Function

func azure functionapp publish auditserver

Check the function published and URL

To get the name of the function published within a resourcegroup

az functionapp function list --name auditserver --resource-group selectid000rg --query "[].name"

to get the name and the URL against which the function is published

az functionapp function list --name auditserver --resource-group selectid000rg --query "[].{name: name, url: invokeUrlTemplate}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment