how to create Azure Functions from Azure python sdk? - azure

Any examples on how to create Azure Functions with Azure Python SDK ?
is https://learn.microsoft.com/en-us/python/api/azure.mgmt.web.models.Site?view=azure-python a correct reference for it?

Explicit examples, at my knowledge there is not. But it's definitely using the azure-mgmt-web package you point at. You need to create an AppPlan (or serverfarm), and then a webapp of kind "functionapp".
The closest to an example would probably to look at what the Azure CLI (written in Python) is doing:
https://github.com/Azure/azure-cli/blob/e0c49d6fd4778b8e0c8884a54bca1716a916763e/src/command_modules/azure-cli-appservice/azure/cli/command_modules/appservice/custom.py#L1613-L1684

Related

What is the main Ad's and Con's using MS Graph API vs MS Azure SDK

We have teh need to interact with our customers AD from Jira in order to handle automatically user onboarding.
For that we have 2 deifferent approach :
Using Microsoft Graph API
We call directly from Jira Script Runner plugin using groovy script POST and GEt methods, this directly within Jira environment
Using Microsoft Azure SDk for python
Using this approach will need to build a python script which is store in the dedicated location on the VM and calling that scrip from Jira using Groovy script
In the first approach we are using only 4 API call only for how request and we are all time scripting within Jira environement.
ON the second approach we need to deal with 2 types of script ( python and groovy)
Based on your advise, do you see what could be the best based on your experience in order to help me chose one or the other ?
Thanks for help
regards
See https://learn.microsoft.com/azure/active-directory/develop/active-directory-graph-api
We strongly recommend that you use Microsoft Graph instead of Azure AD
Graph API to access Azure Active Directory (Azure AD) resources. Our
development efforts are now concentrated on Microsoft Graph and no
further enhancements are planned for Azure AD Graph API. There are a
very limited number of scenarios for which Azure AD Graph API might
still be appropriate;
Hence I will suggest Microsoft Graph
I would follow up to Laurent, and say, the better solution is the solution that has the least amount of complexity while accomplishing everything you need to do.
In this case according to your own post, that is clearly just calling graph API directly from your groovy scripting in Jira.

Is it possible to create a new CosmosDB account using #azure/cosmos sdk?

Pretty sure this is a trivial question but couldn`t find any clue on the #azure/cosmos package documentation.
I'm searching for something like we have in Azure CLI, this is a sample, but in #azure/cosmos package. More help of what I want in az cosmosdb create command documentation.
You are pointing to the Cosmos DB JS SQL SDK, which as the rest of the Cosmos DB SDKs (.NET, Java, Python) is used for Data Plane operations.
Creation of accounts is a Management operation.
You can use ARM templates
You can use the Azure CLI, which you already know
You can use Powershell
There are Azure Management Libraries for JS but they don't seem to include Cosmos DB yet. There are .NET versions though.

Monitor local Azure Functions?

Is it possible to get Information out of the Azure function SDK?
For example the Function URI. Or the count of Functions running local.
Somthing like Swagger for local Azure Functions would be the goal.
Thanks for your help.
I remember trying to use something similar to swashbuckle for Azure Functions, but there was no easy way to integrate it. This may help: AzureFunction Swagger Definition Generator
Azure Function's OpenAPI 2.0 support may provide some of the functionality you are desiring. Note that as of April 2018, it is still in preview.

Creating Azure Functions programmatically

I´m looking at Azure Functions capabilities and the documentation does not say anything about uploading, creating or deleting a Function programmatically, nor anything about listing enabled/disabled Functions. Any ideas on how to do that? The Azure API reference has no section for Azure Functions.
This functionality exists within the Azure CLI toolset.
Here is a guide on creating functions via the CLI
Documentation for the functions segment of Azure CLI
Hopefully these two resources should help get started. If you were looking for a publicly facing API, you may be out of luck.
You can create functions from the cli using:
func new
Alternatively you can pass in some parameters (not required):
func new --language JavaScript --template HttpTrigger --name MyFunction
If you don't pass in the parameters, you are prompted with the questions and you can choose the correct options.
I've done deletion by removing the function specific folder and then deploying the application again.

Is it possible to stop/start an Azure ARM Virtual Machine from an Azure Function?

Runbooks can be used to stop/start classic and ARM Virtual Machines in Azure.
Is this also possible from an Azure Function?
Some good news to update this thread. You will be able to do that now in Azure Functions. The steps are documented here based on HTTP-triggered Functions.
Azure Function role like permissions to Stop Azure Virtual Machines
You may switch out the trigger type to fit your use-case.
See Ling's response above. We've addressed this now. :)
It's not currently possible to do this via the Azure PowerShell commandlets in Azure Functions. You can write against the Azure C# SDK or use the x-plat CLI (if you bring it yourself, as it isn't installed by default). You'll need to upload a cert or use a service account to perform those actions.
FYI - I'm on the Functions team and we're working on improving this story, in the near future. I'll update this answer once it's been made possible.
You can either use the Azure REST API from here -> Docs or make use of the SDK to do the operations.

Resources