2
votes

I'm using a queue trigger to pass in some data about a job that I want to run with Azure Functions(I'm using python). Part of the data is the name of a file that I want to pull from blob storage. Because of this, declaring a file path/name in an input binding doesn't seem like the right direction, since the function won't have the file name until it gets the queue trigger.

One approach I've tried is to use the azure-storage sdk, but I'm unsure of how to handle authentication from within the Azure Function.

Is there another way to approach this?

3

3 Answers

1
votes

In Function.json, The blob input binding can refer to properties from the queue payload. The queue payload needs to be a JSON object Since this is function.json, it works for all languages.

See official docs at https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings

For example, in you function.json,

{
  "name": "imageSmall",
  "type": "blob",
  "path": "container/{filename}",
}

And if your queue message payload is:

{
 "filename" : "myfilename"
}

Then the {filename} token in the blob's path expression will get substituted.

0
votes

Typically, you store connection strings / account keys in App Settings of the Function App, and then read them by accessing environment variables. I haven't used python in Azure, but I believe that looks like

connection = open(os.environ['ConnectionString']).read()

I've found one example of python function which does what you ask for: queue trigger + blob operation.

0
votes

Storing secrets can (also) be done using App Settings.

In Azure, go to your Azure Functions App Service, Then click "Application Settings". Then, scroll down to the "App Settings" list. This list consists of Key-Value pairs. Add your key, for example MY_CON_STR and the actual connection string as the value.

Don't forget to click save at this point

Now, in your application (your Function for this example), you can load the stored value using its key. For example, in python, you can use:

os.environ['MY_CON_STR']

Note that since the setting isn't saved locally, you have to execute it from within Azure. Unfortunately, Azure Functions applications do not contain a web.config file.