Using Pulumi, how can I retrieve function names from a Function App in Azure?
Objective:
My objective is to retrieve all Azure functions and their associated API key for a given Function App.
Issue:
I am unable to find Pulumi documentation on how to programmatically retrieve function names from a Function App.
Then I can rely on the following function to accommodate my need:
await ListWebAppFunctionKeys.InvokeAsync(new ListWebAppFunctionKeysArgs {
Name = appName,
FunctionName = "?",
ResourceGroupName = resourceGroupName
});
Alternative Approach:
I attempted to rely on an HTTP GET request (as a workaround) but observed an Unauthorized error:
var current = Pulumi.Azure.Core.GetClientConfig.InvokeAsync().Result;
var subscriptionId = current.SubscriptionId;
var appName = functionApp.Name;
var url = $"GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appName}/functions?api-version=2022-03-01";
var httpClient = new HttpClient();
var result = await httpClient.GetAsync(url);
if (!result.IsSuccessStatusCode) throw new Exception($"Error: Failed to retrive Azure function names from {appName}");
var json = result.Content.ReadAsStringAsync();
I'm unable to resolve the error. I think I need to create a bearer token but do not know the steps required.
First establish an authorization token:
After an authorization token has been established the consider the following code:
Here's some code for creating an auth token:
Here's the JSON root class for deserialization: