Best place to store environment variables for Azure Function

后端 未结 4 1718
旧时难觅i
旧时难觅i 2021-02-03 23:14

I\'m testing an azure function locally with several api keys. Whats the best place to store environment variables and how do I access them? I tried

System.Enviro         


        
4条回答
  •  梦谈多话
    2021-02-03 23:24

    To store api keys you can use Application Settings. Details: https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings#application-settings

    To get an environment variable or an app setting value, use System.Environment.GetEnvironmentVariable, as shown in the following code example:

    public static void Run(TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        log.Info(GetEnvironmentVariable("AzureWebJobsStorage"));
        log.Info(GetEnvironmentVariable("WEBSITE_SITE_NAME"));
    }
    
    public static string GetEnvironmentVariable(string name)
    {
        return name + ": " + 
            System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
    }
    

    Details: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#environment-variables

    Thanks, Alexey

提交回复
热议问题