Azure file system Read Only Error: Azure function

Manjot Bhathal 1 Reputation point
2021-02-23T02:16:04.517+00:00

I'm deploying a function app which gets data from a public api A & posts it to api B(Timer based). Api A uses Oauth2, where last "Refresh token" received by the user is sent to the api A, to get new "Access Token" & "Refresh Token". New tokens give me the access to get request data from the api A & this cycle repeats next time.
I planned to save the refresh token as a json file & re-write(i.e. udpate the refresh token) it on every execution of the function but on deploying the function I received the following error in the portal(file system is read only). I can't save it to a temp file as I need the new refresh token on the next execution of the function. I have attached my code, host json file, local settings file as well.

I'm using python & vs code for the development(Azure student plan), I can't seem to find any settings relating to changing the read only file system. I found few articles/issues, but I am not able to find any of this advice due to lack of detail/ I don't know what I'm doing. I'm quite new to azure platform.

And, IS THERE A BETTER SOLUTION ALTOGETHER to what I'm trying to implement?

https://tomasherceg.com/blog/post/azure-app-service-cannot-create-directories-and-write-to-filesystem-when-deployed-using-azure-devops
https://stackoverflow.com/questions/53630773/how-to-disable-read-only-mode-in-azure-function-app
https://learn.microsoft.com/en-us/answers/questions/67126/failure-exception-oserror-errno-30-read-only-file.html
https://learn.microsoft.com/en-us/answers/questions/42218/python-37-file-system-is-read-only.html

70862-host-json-file.png70863-local-settings.png
70800-error-message.png70901-my-code-that-updates-the-json-file.png

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,169 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,300 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,591 Reputation points Microsoft Employee
    2021-02-23T07:45:20.087+00:00

    @Manjot Bhathal The file system is read only by default. For file-based persistence, you should instead use the storage bindings which will store the file in blob storage, available to access across function invocations even as it scales out across instances.

    An alternative you could explore is creating a Custom Connector for the Public APIs (if connectors don't exist already) and then leverage Logic Apps to run on a schedule, fetch data from the API A and then call API B.

    Custom Connectors internally perform the same kind of token magic like you are trying to achieve and expects the required details when creating the custom connector. If this works out with the Public API, you could build your solution with almost no code to maintain.

    0 comments No comments