Azure / Azure-Functions

1.12k stars 198 forks source link

Ability to pass in arbitrary properties to an azure function via the function.json file #463

Closed jonathanfishbein1 closed 5 years ago

jonathanfishbein1 commented 7 years ago

I have an HTTP triggered pre-compiled azure function. The function ultimately queries CosmosDB. The reason I am NOT (emphasis, not yelling) using a documenDB binding is because I am querying more than one document.

For unit testing purposes I would like to pass in CosmosDB properties including the endpoint, authKey, databaseId, and collectionId, Currently I am using the ConfigurationManger to grab properties from the local.settings.json file. This strategy wont work if I attempt to unit test the function because the function will not execute within the context of the azure functions runtime.

I would like to be able to pass in CosmosDB properties via local.settings.json/appsettings -> function.json -> pre-compiled Run function.

christopheranderson commented 7 years ago

@brettsam - can he potentially use just a DocumentDB Client here?

jonathanfishbein1 commented 7 years ago

In my search to find out if this functionality exists I have asked this question here

https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app/#comment-135665

at the bottom of the comments section. Here @lindydonna helped me understand the issue and helped me understand what I was looking for.

I also asked here

https://social.msdn.microsoft.com/Forums/azure/en-US/08115bea-9af0-4805-a561-e7ec6b474b0f/is-it-possible-to-pass-in-arbitrary-properties-to-an-azure-function-through-the-functionjson-file?forum=AzureFunctions

where I attempt to explain in more detail why I'm looking for that functionality. Thanks @ahmelsayed for the help there

jonathanfishbein1 commented 7 years ago

Ok So there may be a less intrusive way. Currently if I have the following

let Run(req : HttpRequestMessage, something : string) =

the azure functions runtime will through an exception

"Exception while executing function: Functions.GetAllPr oblems -> Exception binding parameter 'something' -> No value was provided for parameter 'something'."

If instead of throwing an exception that were allowed I could pass in properties to the function while in the unit testing environment and continue using the ConfigurationManager.AppSettings when running in the azure functions runtime

I know you folks are super busy so I appreciate the help you have offered, and any further help you can provide

brettsam commented 7 years ago

@christopheranderson -- he could use DocumentClient to construct the client, but that doesn't help get the database/collection details, which he needs to do from within the function. This sounds like a more general question about "how can I get app settings in unit tests without actually checking in those app settings".

@jonathanfishbein1 -- what about using Environment.GetEnvironmentVariable("") from within your function? That will work in the context of a function and should let you 'pass in' these details for your unit test.

But another question -- we have support for SQL queries in the DocumentDB binding now. Have you tried to use that for querying multiple documents? https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-documentdb#input-sample-with-multiple-documents

jonathanfishbein1 commented 7 years ago

@brettsam thanks for this response. It's an interesting technique. I'm somewhat ambivalent to using global/environment settings with values or applications because they become hidden inputs to my system.

As far as the sql query. My azure function is returning an 'ApiModel' to a JavaScript client. My azure functions .dll is populating the 'ApiModel' from database models. Maybe one sql query could do that, I'm not sure, but i like using strongly typed linq more either way.

Is the ability to pass in arbitrary values to an azure function via the function.json file a good idea? would the functions team consider it?

stevetayloruk commented 7 years ago

Hi,

I have a similar issue. I want to pass in a binding to just the CosmosDB so I can build the query based on a combination of business logic and route params.

So being able to pass in arbitary values i think would be a good thing.

Thanks

fabiocav commented 5 years ago

Closing this as the original question was answered, there have been enhancements in this area and this issue is stale.

@stevetayloruk please let us know if you have additional questions/issues.