1

I've come across a lot online saying it's bad practice to edit the Function.Json as a post-build process. The recommendations are setting the App.Settings on the Azure Function but what I want to do it replace the bindings in the Function.Json how do I do that in the app settings? I essentially want the same values in my local.settings.json to override the Function.Json

My local.settings.json

    {
....
  "bindings": [
        {
          "type": "queueTrigger",
          "direction": "in",
          "name": "myQueueItem",
          "queueName": "dev-inbound",
          "connection": "connectionStringV1"
        }
      ]
...
}

3 Answers 3

1

Okay so in the app settings I added a new key called "bindings" and simply added fields in as a JSON object. This will override the bindings in the Function.Json file

Sign up to request clarification or add additional context in comments.

2 Comments

this does not work
Strange, it worked for me at the time?
0

Correct way to do it is to use %VARIABLE_NAME% in function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "msg",
      "type": "serviceBusTrigger",
      "direction": "in",
      "queueName": "%QUEUE_NAME%",
      "connection": "SERVICE_BUS_CONNECTION_STRING"
    }
  ]
}

Comments

0

To use values from the appsettings.json file for your binding configuration, you can use the ${} syntax. For example, if you want to specify the connection string for a storage account, you could set the value in appsettings.json like this:

{
  "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net"
}

And in your function.json file, you could use the ${} syntax to reference the connection string like this:

{
  "name": "inputBlob",
  "type": "blob",
  "direction": "in",
  "path": "mycontainer/{name}",
  "connection": "${AzureWebJobsStorage}"
}

This will ensure that the connection string for the storage account is read from the appsettings.json file and used as the connection string for the inputBlob binding.

Note that the ${} syntax can be used to reference any key-value pair in the appsettings.json file, not just connection strings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.