I'm using the new tooling for Azure Functions projects in VS2017 Preview and have ported some functions from the Azure portal to the new projects.
I'm binding to an Azure Document DB - it's working fine, but when I use the DocumentDB
attribute I have to supply the database name as the first parameter.
In my case it's the DEV database for now .. but of course there will be other environments - is there a way I can pick up the database name via an application setting for the function app?
[FunctionName("TimerTriggeredFunction")]
public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log,
[DocumentDB("my-db-DEV", "MyCollection")] IEnumerable<dynamic> inputDocuments)
Yes, you can use app settings for these values by using the %%
auto resolve syntax for app settings. For example, if you've added app settings named DB_DEV
and COLLECTION_DEV
(either in the portal, or when running on your local box), you can reference those in your attribute like so:
[DocumentDB("%DB_DEV%", "%COLLECTION_DEV%")]
Those app settings will then be resolved at runtime. The "Resolving App Settings" section in our documentation here explains this in more detail.
I'd overlooked the fact that the Azure Cosmos DB connection string can be specified via the local.settings.json
file for my Azure function project.
It's in here that I'd provide the appropriate connection string for the environment I'm targetting. Then I can use consistently named Databases and Collections within those accounts, meaning the function signature is correct in all environments.
[DocumentDB("my-db", "MyCollection")] IEnumerable<dynamic> inputDocuments
And provide the connection string in local.settings.json
under the default key, AzureWebJobsDocumentDBConnectionString
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