Azure App Service (Windows) Config Variable

%3CLINGO-SUB%20id%3D%22lingo-sub-799573%22%20slang%3D%22en-US%22%3EAzure%20App%20Service%20(Windows)%20Config%20Variable%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-799573%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22post-text%22%3E%3CP%3EI'm%20having%20an%20issue%20reading%20env%20variables%20on%20Azure%20App%20Service%20Windows%20instance.%20I%20use%20dotenv%20nodejs%20package%20for%20storing%20my%20env%20variables%20in%20.env%20file.%20It%20works%20perfectly%20fine%20on%20my%20local%20machine%20(Windows%2010)%2C%20but%20the%20same%20does%20not%20when%20hosted%20on%20a%20Windows%20App%20service.%20I%20tried%20some%20troubleshooting%20by%20printing%20out%20the%20env%20variables%20at%20run%20time%20and%20I%20get%20blank%20output%20for%20the%20same.%20Somehow%20it's%20not%20able%20to%20read%20the%20variables%20in%20the%20.env%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20also%20ensured%20that%20the%20.env%20file%20and%20the%20entries%20are%20intact%20on%20the%20deployed%20host%20by%20logging%20onto%20the%20console%20in%20the%20portal.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20am%20I%20doing%20wrong%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-799573%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20App%20Service%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-809853%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20App%20Service%20(Windows)%20Config%20Variable%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-809853%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F384773%22%20target%3D%22_blank%22%3E%40eynarain%3C%2FA%3E%26nbsp%3BDid%20you%20try%20setting%20the%20environment%20variables%20using%20the%20Configuration%20settings%20for%20your%20webapp%3F%3C%2FP%3E%3CP%3ECheck%20out%20this%20screenshot%2C%20I%20guess%20this%20should%20help%20you%20setting%20your%20environment%20variables.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127375i3327742966A9070B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Screenshot_145.png%22%20title%3D%22Screenshot_145.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EYou%20may%20find%20more%20info%20on%20this%20at%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Fconfigure-common%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Fconfigure-common%3C%2FA%3E%3CBR%20%2F%3EI%20hope%20this%20solves%20your%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-810425%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20App%20Service%20(Windows)%20Config%20Variable%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-810425%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394060%22%20target%3D%22_blank%22%3E%40akhilvatts%3C%2FA%3EThat%20did%20the%20trick.%20Thanks%20for%20letting%20me%20know%20of%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1875566%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20App%20Service%20(Windows)%20Config%20Variable%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1875566%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394060%22%20target%3D%22_blank%22%3E%40akhilvatts%3C%2FA%3E%26nbsp%3Bhow%20do%20you%20suggest%20to%20work%20with%20Application%20Settings%20on%20local%20dev%20environments%3F%26nbsp%3B%20Using%20.evn.local%2C%20.env.qa%20and%20.env.prd%20allows%20me%20to%20have%20specific%20environment%20variables%20managed%20through%20my%20codebase.%26nbsp%3B%20I%20use%20the%20pipeline%20to%20convert%20.env.%3CENVIRONMENT%3E%20to%20.env%20and%20then%20inject%20sensitive%20values%20against%20keys%20such%20as%20password%20from%20a%20vault.%3C%2FENVIRONMENT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EManaging%20environment%20variables%20through%20Application%20Settings%20means%20more%20overhead%20whenever%20I%20need%20to%20introduce%20new%20variables%2C%20especially%20non-sensitive%20ones.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1876590%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20App%20Service%20(Windows)%20Config%20Variable%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1876590%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20seems%20like%20this%20was%20a%20specific%20problem%20with%20my%20Python%20Flask%20application.%26nbsp%3B%20Since%20Azure%20App%20Service%20uses%26nbsp%3B%3CSTRONG%3Egunicorn%3C%2FSTRONG%3E%20to%20start%20Python%20applications%20and%20not%20the%20Flask%20CLI%2C%20the%20.env%20file%20was%20not%20getting%20loaded%20into%20the%20project%20because%20the%20Flask%20CLI%20will%20typically%20load%20the%26nbsp%3B%3CSTRONG%3Epython-dotenv%3C%2FSTRONG%3E%20package.%26nbsp%3B%20Once%20I%20loaded%20it%20myself%20into%20main.py%2C%20it%20started%20working%20again.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I'm having an issue reading env variables on Azure App Service Windows instance. I use dotenv nodejs package for storing my env variables in .env file. It works perfectly fine on my local machine (Windows 10), but the same does not when hosted on a Windows App service. I tried some troubleshooting by printing out the env variables at run time and I get blank output for the same. Somehow it's not able to read the variables in the .env file.

 

I also ensured that the .env file and the entries are intact on the deployed host by logging onto the console in the portal.

 

What am I doing wrong?

4 Replies

@eynarain Did you try setting the environment variables using the Configuration settings for your webapp?

Check out this screenshot, I guess this should help you setting your environment variables.

Screenshot_145.png

You may find more info on this at: https://docs.microsoft.com/en-us/azure/app-service/configure-common
I hope this solves your problem.

 

Thanks

@akhilvattsThat did the trick. Thanks for letting me know of this.

Hi @akhilvatts how do you suggest to work with Application Settings on local dev environments?  Using .evn.local, .env.qa and .env.prd allows me to have specific environment variables managed through my codebase.  I use the pipeline to convert .env.<environment> to .env and then inject sensitive values against keys such as password from a vault.

 

Managing environment variables through Application Settings means more overhead whenever I need to introduce new variables, especially non-sensitive ones.

It seems like this was a specific problem with my Python Flask application.  Since Azure App Service uses gunicorn to start Python applications and not the Flask CLI, the .env file was not getting loaded into the project because the Flask CLI will typically load the python-dotenv package.  Once I loaded it myself into main.py, it started working again.