In this Azure article, we will discuss Azure Function Environment Variable. How to access environment variables to use in your Azure Function, etc.
Table of Contents
Azure Function Environment Variable
Environment Variable helps you to store any custom settings for your Azure Function. This is the main purpose of the Environment Variable.
You can configure or manage these custom settings in the Application Settings of the Azure Function App. To reach out to this option, You can log in to the Azure Portal, navigate to your Azure Function App, and click on the Configuration from the left side menu on your Azure Function App page. Now you can find the option Application settings.

We can use the GetEnvironmentVariable() to access the value of the Environment Variable.
Example
If we will see an example below is the MyNewHTTPNewFunction Azure Function, where we have used the GetEnvironmentVariable method.
[FunctionName("MyNewHTTPNewFunction
")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("MyNewHTTPNewFunction processed a request.");
log.LogInformation(GetEnvironmentVariable("MY_PRODUCT_NAME"));
var NewSetting = Environment.GetEnvironmentVariable("MyNewSetting", EnvironmentVariableTarget.Process);
return Task.FromResult(req.CreateResponse(HttpStatusCode.OK, new { setting= NewSetting }));
Now, in your local.settings.json file of your Azure Function, you should mention “MY_PRODUCT_NAME” and the value for this key. GetEnvironmentVariable(“MY_PRODUCT_NAME”) retrieves the value for this key, which is “Your Product name” in this case.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"MY_PRODUCT_NAME": "Your Product Name"
}
}
You may also like following the below Articles
Final Thoughts
In this Azure article, we discussed Azure Function Environment Variable. Thanks for reading this article !!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
