Home > OS >  When I run an azure function locally (which uploads a data to cosmos), does it replace the existing
When I run an azure function locally (which uploads a data to cosmos), does it replace the existing

Time:04-12

Note: In the question below, I have not yet deployed the function.

I have an azure function that I test locally on VScode (azure extension). This function is blob triggered i.e. triggered when an image is uploaded to a certain blob container (say c) and later uploads a certain metadata (dict) on cosmos. I have also linked my blob storage my vscode. The storage container c has a lot of images already (200 ). When I run my azure function locally (on VScode), it seems to be running the function on all existing images again. It is an issue I have asked elsewhere enter image description here

But I have a second question. If this function is running on all triggers on VSCode (not deployed yet), is it replacing/re-writing all my data on cosmos (my azure function uploads some data to cosmos in the end)

Edit:

My blob trigger/azure function is way too long so I will just post on how it triggers

def main(myblob: func.InputStream, doc: func.Out[func.Document]):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

    blob_val = myblob.read()
    .
    .
    .

and host.json:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }
}

CodePudding user response:

Regardless of where the Function is running (your local machine, Azure, any other supported hosting options), if your configuration has the Cosmos DB Connection String of a real Cosmos DB account, then the Function will perform the update on that account.

Simply the answer to your question is: The update will be performed on the account your Connection String points to regardless of where the Function is running.

One alternative, if you want to do local testing, is to use the Cosmos DB Emulator and have your local configuration Connection String use the Emulator's Connection String, so your local testing won't affect any real account.

And you can have that setting overwritten when running on Azure by adding that setting but pointing to your real Cosmos DB account on the App Settings or Connection Strings.

  • Related