Open cdeil opened 4 years ago
I see you sometimes use .env
, sometimes local.settings.json
.
Are they interchangeable to add env vars when developing locally?
Any pros or cons when to use one or the other?
Sorry I never got the notification for this but thanks for the issue.
local.settings.json
is automatically created by the Azure functions extension to develop locally. You could use these to store all your environment variables when developing locally and it should work as expected.
I tend to use .env
for non-Azure related environment variables (passwords, usernames, tokens etc.) as it's a common best practice/workflow I have been using for a while to store secrets that should not be in an app/repository. Regardless of where the solution is to be deployed (i.e. Azure, AWS, Heroku).
Looking at https://pypi.org/project/python-dotenv/ I'm not sure if those functions will throw an error actually, or if you're just supposed to call them without try-except, and if they don't find a .env they will not modify the env, but that's fine, not try-except needed?
You do not need a try / except normally when using the python-dotenv. I added this for my own debugging sake (if working locally it should be loading the env variables from the local .env file. If the function is running on the deployed Azure instance env variables will all be loaded from the secrets provided in the function configuration variables).
But will make sure I will add the imports! let me know if you have any more questions @cdeil
Tania - thanks for the tutorial!
Missing import for find_dotenv and load_dotenv in this file:
https://github.com/trallard/pycon2020-azure-functions/blob/41837c13b6bc142079182cbc6bdfc8909b1be84a/solutions/03-full-pipeline/blob-manipulation/blob_manipulation.py#L23-L29
The
ImportError
is masked because of theexcept
that will catch any error.Looking at https://pypi.org/project/python-dotenv/ I'm not sure if those functions will throw an error actually, or if you're just supposed to call them without try-except, and if they don't find a
.env
they will not modify the env, but that's fine, not try-except needed?