Share via

Create Azure Function using .NET SDK

Nisha Kaushik 1 Reputation point
2020-10-14T04:05:05.58+00:00

I'm trying to create an Azure Function with Linux OS and Python 3.8 runtime using Azure management .NET SDK. But it always creates Windows machines and there doesn't seem to be any way to specify that the OS should be Linux.

Additionally on the portal, we can specify python version 3.8, but the same is not available through the API.

I'd like help on setting creating Azure Functions App and then uploading the functions from the blob storage.
I can currently create Azure functions app but the OS is windows.
I can't currently upload/deploy the functions within this new app.

Following is the code that I'm using:
using System;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.AppService.Fluent;
using Microsoft.Azure.Management.AppService.Fluent.FunctionApp;
using Microsoft.Azure.Management.AppService.Fluent.FunctionApp.Definition;
using Microsoft.Azure.Management.AppService.Fluent.FunctionApp.Update;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.AppService.Fluent.Models;

var azure = Azure
.Configure()
.Authenticate(credentials)
.WithDefaultSubscription();

        var dbc = azure.AppServices.FunctionApps.Define("FuncTest2232")
            .WithRegion(Region.USEast)
            .WithExistingResourceGroup("testRes33")
            .WithExistingStorageAccount(sta)
            .WithLatestRuntimeVersion()
            .WithRuntimeVersion("Python|3.8")
            .WithAppSetting("FUNCTIONS_WORKER_RUNTIME", "python")
            .WithStickyAppSetting("kind", "functionapp,linux")
            .WithAppSetting("FUNCTIONS_EXTENSION_VERSION", "~3")
            .WithPythonVersion(PythonVersion.V34)
            .Create();

The above code ends up creating a functions app but with Windows OS and Python 3.6 installed (this is not possible through the portal, i.e. a Python environment with Windows OS, but this gets created from the above code). Deployment to this environment is not possible either through the portal or through VS code.

Thanks

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.