Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8874

How to call azure function with params

I am trying to use Azure function with to invoke the same function with different time and different param(url). I didn't find any good example that shows how to pass some data. I want to pass link to function. My code is:

var rp = require('request-promise');
var request = require('request');

module.exports = function (context //need to get the url) {  

and the function

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 */1 * * *"
    }
  ],
  "disabled": false
}

Upvotes: 2

Views: 4408

Answers (2)

Garth Mason
Garth Mason

Reputation: 8001

Another possibility is if your parameters are stored somewhere in e.g. Azure Document DB (Cosmos).

You could still use a TimerTrigger to invoke the function, and include a DocumentDB input binding allowing you to query for the specific parameter values needed to execute the function.

Here's a C# example triggered by Timer, with a DocumentDB input binding. Note: I'm using the latest VS2017 Preview tooling for Azure functions.

[FunctionName("TimerTriggerCSharp")]
public static void Run(
   [TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, TraceWriter log, 
   [DocumentDB("test-db-dev", "TestingCollection", SqlQuery = "select * from c where c.doc = \"Test\"")] IEnumerable<dynamic> incomingDocuments) 
 {..}

With the following binding json:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */5 * * * *"
    },
    {
      "type": "documentDB",
      "name": "incomingDocuments",
      "databaseName": "test-db-dev",
      "collectionName": "TestingCollection",
      "sqlQuery": "select * from c where c.docType = \"Test\"",
      "connection": "my-testing_DOCUMENTDB",
      "direction": "in"
    }
  ],
  "disabled": false
}

Upvotes: 0

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35124

If your settings are relatively static (but you still don't want to hard code them), you may use app settings to store them, and then read e.g.

let url = process.env['MyUrl'];

If URL should be determined per request, you may use HTTP trigger and read the URL from query parameters:

let url = req.query.myurl;

I'm not sure what exactly you are trying to achieve with parameterized timer-triggered function.

Upvotes: 2

Related Questions