Hello : @Xiuyang Bobby Sun Unfortunately, you cannot change the environment variables while the function is running. Environment variables are set when the function app starts up and are read-only during the lifetime of the function app.
If you need to store data that can be updated during the lifetime of the function app, you can use other storage options such as Azure Blob Storage, Azure Table Storage, or Azure Cosmos DB.
For your specific use case, you could use a flag or a variable to keep track of whether the data has been fetched or not, and update that variable accordingly.
For example, you could use a boolean variable called fetched
and set it to False
initially. Once you fetch the data, you can set fetched
to True
. Here's an example:
import os
fetched = False
def main(req): global fetched
if not fetched:
# fetch data
fetched = True
else: # data has already been fetched
pass
This way, you can keep track of whether the data has been fetched or not without relying on environment variables.
I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.