Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions, make local.settings.json values take precedence over System environment variables

In Azure Functions you can pass dummy environment variables through local.settings.json, which you set as application settings (ideally with key vault) when you deploy.

However when you run locally, i.e. func host start --function=MyFunction it always takes your locally defined environment variables over those in the settings file.

I want to access the variable in local.settings.json instead of the value in my environment variables.

I can't find one, and it's annoying if you want to test without having to manually change your environment variables.

Links: Python docs on env vars.

Local.settings.json docs

Existing question on how to store environment variables

like image 664
jabberwocky Avatar asked Sep 17 '25 13:09

jabberwocky


1 Answers

For now this is not supported if you are using python function. You could get a prompt that the key is skipped.

enter image description here

So if you want to use same setting in the local you could read the json file the get the value.

Below is my code to access the testkey in the local.settings.json.

    ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    with open(ROOT_DIR+'\\local.settings.json') as f:
        data = json.load(f)
        testkey=data['Values']['testkey']
        logging.info(testkey)

enter image description here

like image 174
George Chen Avatar answered Sep 20 '25 11:09

George Chen