I have a small function that takes an array of US telephone area codes and returns an array of area codes paired to the state they are in.
The "master list" of area codes to states is a long variable in my function. I'd like to put that in a CSV file instead.
I'm a beginner to using Azure Functions but, even when the file is in the root folder, Get-Content .\filename.csv
does not work.
It's never really a good idea to reference absolute paths as things may change. To use a variable that will always point you to the correct path you can use:
$EXECUTION_CONTEXT_FUNCTIONDIRECTORY
which will return the current folder your Azure Functions runs from.
To use this in your question at hand:
Get-Content -Path "$EXECUTION_CONTEXT_FUNCTIONDIRECTORY\filename.csv"
Documentation on this: https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function#powershell-php-python-bash-batch-and-other-scripting-languages
The path to your Azure Function directory is
D:\home\site\wwwroot\<YourFunctionName>
To load the CSV file, use the following in your PowerShell script,
Get-Content D:\home\site\wwwroot\<YourFunctionName>\filename.csv
Here's a sample output for loading the areacode-to-state mapping file,
2017-03-11T09:21:57.185 Function started (Id=9c93e8cf-4cf0-487e-b86e-02e57b41b8de)
2017-03-11T09:21:58.357 Area code,State,State code
2017-03-11T09:21:58.357 201,New Jersey,NJ
2017-03-11T09:21:58.357 202,"Washington,DC",DC
2017-03-11T09:21:58.357 203,Connecticut,CT
2017-03-11T09:21:58.357 205,Alabama,AL
....<more logging>....
Additional tooling and resources:
i. Kudu console - You may use the Kudu console to navigate through the directory structure of your Function App. I sometimes use the Kudu console to test the run.ps1
script outside the Azure Functions runtime.
To use the Kudu console, perform the following steps:
ii. Bring your own modules - You may also load your own custom modules and use them in your run.ps1
script. Details on how to achieve this are provide here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With