Matt Hernandez 023c4817a2 Update Azure documentation.
Cleaned up the formatting, corrected some typos, updated the credentials
guide to cover interactive login, and cleaned up the quick start.
2017-06-09 14:55:54 -07:00

2.0 KiB

Read this on the main serverless docs site

Other Bindings

The Azure Functions plugin also supports additional input and output bindings. These work by setting the direction explicitly. The properties go under the x-azure-settings property and match the same properties expected in the function.json, with the exception of "type" which is the first property's key.

You can learn about all the bindings Azure has to offer here on the official documentation.

Example

This is an example of outputting data to Document DB.

# serverless.yml

functions:
  example:
    handler: handler.hello
    events:
      - queue: hello
        x-azure-settings:
            name: item #<string>, default - "myQueueItem", specifies which name it's available on `context.bindings`
            connection: AzureWebJobsStorage #<string>, default - "AzureWebJobsStorage", environment variable which contains Storage Account Connection String
      - documentDB:
        x-azure-settings:
            name: record # Name of input parameter in function signature>",
            databaseName: myDocs # "<Name of the DocumentDB database>",
            collectionName: todo # "<Name of the DocumentDB collection>",
            createIfNotExists: true
            connection: docDBAppSetting # "<Name of app setting with connection string - see below>",
            direction: out
// handler.js

'use strict';

module.exports.hello = function(context, item) {
  context.log("Received item: ${item}");
  context.bindings.record = {
      hello: "world"
  }
  context.done();
};