I am using typescript/node based azure functions with cosmos/sql api. Right now, I have written all my functions logic using the #azure/cosmos client. I am actively trying to refactor those functions to use input/output bindings instead; however, I am having issues finding examples of deleting entities using bindings.
Example input binding:
{
"type": "cosmosDB",
"direction": "in",
"name": "inputDocument",
"databaseName": "test",
"collectionName": "test",
"connectionStringSetting": "COSMOS_DB",
"id": "{id}",
"partitionKey": "/tenantId",
"sqlQuery": ""
}
So, to simplify things, my questions are:
Can bindings be used to perform delete operations?
Is there a way to elegantly inject an #azure/cosmos client in typescript using function bindings? I saw some examples in C#, but I could not find anything typescript related.
Any advice/suggestions would be greatly appreciated! Thank you so much :)
Related
I see many templates online using primaryEndpoints ouput parameter in ARM templates, but I am not sure how they actually found it as it's not mentioned in the docs. What is the best way to find out the available outputs for a resource?
one of the way is to output the whole object with all properties and values.
"outputs": {
"myObject": {
"type": "Object",
"value": "[reference(parameters('myResources'))]"
}
you can also use resource explorer to browse resources that are provissioned
When writing the outputs part of ARM template how do the do what properties are available for a resource. in the below example for public ip resource how do I find out dnsSettings.fqdn or .ipAddress is available
"outputs": {
"fqdn": {
"value": "[reference(parameters('publicIPAddresses_name')).dnsSettings.fqdn]",
"type": "string"
},
"ipaddress": {
"value": "[reference(parameters('publicIPAddresses_name')).ipAddress]",
"type": "string"
}
}
Your ask is related to Retrieve FQDN of Azure SQL from a linkted template question.
The easiest way to accomplish your requirement is illustrated in below screenshot.
Hope this helps!! Cheers!!
Note: If you think your question has been answered then please 'accept' it, if just helped then click "This answer is useful" and provide an up vote. This can be beneficial to other community members reading this thread.
One way I've found, using only ARM, is to output the whole object:
"outputs": {
"ipaddress": {
"type": "Object",
"value": "[reference(parameters('publicIPAddresses_name'))]"
}
When you apply the policy, the output will show all the possible properties and their values.
You can view the whole data structure in json at https://resources.azure.com.
you dont really know, because some properties are amended by default (and the other answer doesnt mention that at all, which could mislead you badly). One thing you can do is look at the rest api definition of the resource and use Full reference to the resource, that way you will always get what you see in the api definition.
reference(parameters('publicIPAddresses_name'), 'api-version', 'Full')
but, object structure will be different, as far as I remember you'd need to access properties of the object for the most of the output. What I tend to do is - create a template that does nothing but output the existing object I'm interested in and run it and examine the output.
Outputs are almost never needed so it's not that big of an issue in my mind.
Rest Api definitions: https://learn.microsoft.com/en-us/rest/api/azure/
In node.js we can set context using agent.setContext(), what will be python alternative of using this way?
Currently I am using below code to set new context:
res = {
"fulfillmentText = "This is a test",
"outputContexts": [
{
"name": "projects/project_id/agent/sessions/session_id/contexts/your_context",
"lifespanCount": 5,
"parameters": {
"foo": "bar",
"foo1": "bar1"
}
}
],
}
return res
Is there any simpler way?
Thanks in advance.
Note : It seems like node.js have dialogflow-fulfillment library to ease up the things. Is there any similar fulfillment library for python as well?
The Node.js dialogflow-fulfillment library is owned and maintained by Dialogflow/Google. There is no "official" Dialogflow Python fulfillment library but there are a couple community efforts you can fork:
Flask extension: https://github.com/treethought/flask-assistant
Response generation helper: https://github.com/pragnakalp/dialogflow-webhook-response-libary-in-python
There is no standard python fulfillment library at this time. Sounds like an opportunity for you!
The format for setting output contexts looks correct, and isn't really much more difficult than the equivalent in JavaScript. How much simpler do you want it?
This is to find out if something I'm attempting is even possible...
I've seen several examples of developing an entry ARM template (azuredeploy.json) that refs/imports an external child resource template (eg: azuredeploy.sql.server.json) within which is defined a new SQL Server as well as -- within the sql server's resources section -- nested resources, such as a firewallrule.
I've seen one example (https://blogs.msdn.microsoft.com/azuresqldbsupport/2017/01/11/arm-template-to-deploy-server-with-auditing-and-threat-detection-turned-on/) where the entry/parent ARM template (eg: azuredeploy.json) defines the SQL Server, and instead of defining the firewall rules as a nested resources, defines the firewall rules in parallel, using dependsOn to define execution order.
That appears to be a bit more maintainable/less nested than the first approach.
But I'd like to push it further, where the above resources are all defined in external templates: azuredeploy.json invoking azuredeploy.sql.server.json and azuredeploy.sql.server.firewallRules.json
Unfortunately, I've not found a single example of the above approach.
I've tried for most of the afternoon -- but having changed slashes of ids and names to every configuration imaginable, have run over and over again into:
Code=InvalidTemplate
Message=Deployment template validation failed: 'The template resource {resource-name}'
for type {resource-type} has incorrect segment lengths.
So the questions are:
a) any reason it should not be done this way? (I felt it allowed for a more modular set of arm templates, that could be referenced from a flat entry arm file, only requiring a correct set of 'dependsOn' attributes being defined)
b) can the above actually be done?!
c) is there an online example to study of the above approach and understand my approach error?
d) Just in case: when it's giving the error messages regarding the segment lengths...any chance it's getting itself confused, and it's taking into account "Microsoft.Resources/deployments", when it should be taking into account only "Microsoft.Sql/servers" and "Microsoft.Sql/servers/firewallRules"?
Much appreciated if anybody can advance me on this sticking point.
Yes, you should be able to do this, see: https://learn.microsoft.com/en-us/azure/templates/microsoft.sql/servers/firewallrules
The error you posted suggests that you're missing a name segment or type segment - those must match as in the example below.
"type": "Microsoft.Sql/servers/firewallrules",
"apiVersion": "2015-05-01-preview",
"name": "[concat(parameters('serverName'), '/', 'AllowAllWindowsAzureIps')]",
"location": "[resourceGroup().location]",
"properties": {
"endIpAddress": "0.0.0.0",
"startIpAddress": "0.0.0.0"
}
So your name property will be something like
sqlServerResourceName/whateverYouWantToNameTheFirewallRules - and type exactly as in the example above.
The Visual Studio Code documentation provides example tasks.json configuration that allows either typescript compilation, or markdown compilation. It does not clarify how to achieve both simultaneously.
How can that be done?
Here is a summary of the two examples...
Typescript Example
If I want VSCode to perform a typescript build step, the directions say I need to install typescript (npm install -g typescript) and then define the following task:
{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"showOutput": "silent",
"args": ["*.ts"],
"problemMatcher": "$tsc"
}
Markdown Example
If I want VSCode to perform a Markdown build step, the documentation says I could install a markdown plugin of my choice (e.g. npm install -g marked), and then define a task:
{
"version": "0.1.0",
"command": "marked",
"isShellCommand": true,
"args": ["sample.md", "-o", "sample.html"]
}
Now What?
Evidently, the tasks.json may contain exactly one JSON object. Thus I cannot simply join both definitions above with a comma. On the other hand, it is possible to have multiple tasks defined within the overall task definition:
{
"version": "0.1.0",
"command": "<what goes here?>",
"isShellCommand": true,
"suppressTaskName": true, //or false?
"tasks": [
{
"taskName": "Launch Typescript"
},
{
"taskName": "Launch Markdown"
}
]
}
The above is a skeleton of legal syntax, but it is unclear how to complete the story. I am aware of discussion here and there about how to solve these kinds of issues, but there seems to be a fundamental disconnect. For example, how does VSCode know that it is supposed to execute both tasks when I press ctrl+shift+b?
Assuredly the developers of VSCode have a more direct and simpler way to accommodate multiple build tasks. Does anyone know what that is?
You are almost at the right answer.
You can define multiple build task, as shown in your last example.
What you didn't realize is that you can override global properties within the task. Meaning in one task, you can define "command" and "args" one way and in the other define it with totally different values.
In a sense, copy the meat of two examples you have above into each task in your last example