4

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

jabberwocky
  • 995
  • 10
  • 18
  • 1
    So you want to use the settings in the local.settings.json file instead of the value in the configuration? – George Chen Apr 01 '20 at 13:52
  • I believe app settings could be accessed directly if I were in .net framework but I'm working in Python. (https://learn.microsoft.com/en-gb/dotnet/api/system.configuration.configurationmanager.appsettings?view=netframework-4.8) – jabberwocky Apr 01 '20 at 13:52
  • @GeorgeChen, yes precisely. Instead of the value stored in my laptops environment variables. – jabberwocky Apr 01 '20 at 13:53

1 Answers1

4

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

George Chen
  • 13,703
  • 2
  • 11
  • 26