I was following this documentation and trying to run a simple shell script in a vm using this.
https://learn.microsoft.com/en-us/rest/api/compute/virtual%20machines%20run%20commands/runcommand#runcommandinputparameter
But what needs to be the content of the body of the post request is not clear. The commandID can be RunShellScript but where does we provide the script value.
I have tried a body like this
{
commandId: "RunShellScript",
script: "/path/scriptname"
}
with other options
script: 'scriptname'
script: 'sh scriptname'
and other each resulting in
{
"error": {
"code": "BadRequest",
"message": "Error converting value "/home/admin1/quick-python-test.sh" to type 'System.Collections.Generic.List`1[System.String]'. Path 'script', line 3, position 52.",
"target": "runCommandInput.script"
}
}
Can anyone help me how to do it properly? I am new to Azure.
To run the bash script in the VM through Azure REST API, here is the sample body for the request:
{
"commandId": "RunShellScript",
"script": [
"echo $arg1 $arg2"
],
"parameters": [
{
"name": "arg1",
"value": "hello"
},
{
"name": "arg2",
"value": "world"
}
]
}
Related
I am testing the setting of simple dashboard examples using Azure CLI. Using docs The structure of Azure dashboards This file is a single tile (a small square of browser window) that outputs a short message. I used the following command in VS Code terminal:
az portal dashboard import --name "mySingleTileDashboard1" --resource-group "example-resources_copy" --input-path singleTileDashboard.json
Here is the terminal output showing the .JSON script.
{
"id": "/subscriptions/xxxxxxxxxxxx/resourceGroups/example-resources_copy/providers/Microsoft.Portal/dashboards/mySingleTileDashboard1",
"lenses": {
"0": {
"metadata": null,
"order": 0,
"parts": {
"0": {
"metadata": null,
"position": {
"colSpan": 3,
"metadata": null,
"rowSpan": 2,
"x": 0,
"y": 0
}
}
}
}
},
"location": "westus",
"metadata": {
"inputs": [],
"settings": {
"content": {
"settings": {
"content": "## Dashboard Overview\r\nSingle tile example. Code lifted from azure-portal-dashboards-structure",
"subtitle": "",
"title": ""
}
}
},
"type": "Extension/HubsExtension/PartType/MarkdownPart"
},
"name": "mySingleTileDashboard1",
"resourceGroup": "example-resources_copy",
"tags": {
"hidden-title": "Created via API"
},
"type": "Microsoft.Portal/dashboards"
}
The portal shows that the dashboard has been set. The Overview shows all parameters present. But when I use "Go to dashboard" I get an error page:
Dashboard 'arm/subscriptions/xxxxxxxxxx/resourcegroups/example-resources_copy/providers/microsoft.portal/dashboards/mysingletiledashboard1' no longer exists. It was previously published to resource group 'example-resources_copy' in subscription 'xxxxxxxxxxxxx'.
I followed through on the error using Resolve errors for resource not found The Activity Log showed that the Set Dashboard Succeeded.
The doubt I had, in my script, was the following line:
"type": "Extension/HubsExtension/PartType/MarkdownPart"
The docs show the line to be Extension[azure]/ ... etc. However I tried both versions but got the same result.
Previously I have only set a blank dashboard via script. And it worked. Here it doesn't. So I have a suspicion the line with the MarkdownPart may be screwing things up.
I try to update my json file with GitHub API. I found some solution.
Need to make this POST request https://api.github.com/repos/:user/:repo/git/trees with a body like this:
{
"base_tree": "{{sha-base-tree}}",
"tree": [
{
"path": "fil1.json",
"mode": "100644",
"type": "blob",
"content": "updated text"
}
]
}
But problem with a content variable. I can't pass a json type to this. If I try to pass a json like this {"files": [{"image": "link"}]}:
{
"base_tree": "{{sha-base-tree}}",
"tree": [
{
"path": "fil1.json",
"mode": "100644",
"type": "blob",
"content": "{"files": [{"image": "link"}]}"
}
]
}
I'm getting this error
{
"message": "Problems parsing JSON",
"documentation_url": "https://docs.github.com/rest/reference/git#create-a-tree"
}
I read the documentation and I found some Custom media types for blobs https://docs.github.com/en/rest/reference/git#custom-media-types-for-blobs Maybe it is my case, but I can't understand how to use it.
Can you help me how to update a json file with GitHub API programmatically?
I have seen lots of answer of how to debug a lambda function offline in vscode and I have got that working, to the extent I can set breakpoint and step through it.
However I am unsure how to specify the payload input for the lambda function for testing.
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "Downloads:charge.handler (nodejs10.x)",
"invokeTarget": {
"target": "code",
"projectRoot": "",
"lambdaHandler": "charge.handler"
},
"lambda": {
"runtime": "nodejs10.x",
"payload": {},
"environmentVariables": {}
}
}
]
}
It seems whatever I put into the payload json field, I only ever see an empty param object when my lambda function runs. I also have an ssm key saved on the aws server. Will that automatically be available to my locally debugged lambda function which I have setup with with SAM CLI, Docker and AWS CLI?
Any help would be greatly appreciated.
Thanks,
Greg
Okay so I wasn't specifying the payload properly.
Should be:
"payload": { "json": { "body": {
"item1": 1, "item2": 2, ...
}}}
I am trying to deploy this ARM template
/* example_template.json */
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"var": {
"type": "string",
"defaultValue": "
echo ${VARIABLE}
",
"metadata": {
"description": "some description"
}
}
},
"resources": [],
"outputs": {
"ouput": {
"type": "string",
"value": "[string(parameters('var'))]"
}
}
}
which successfully outputs what I want:
"outputs": {
"ouput": {
"type": "String",
"value": "\n echo ${VARIABLE}\n "
}
}
The problem is, if I am trying to use this in a bash script, $VARIABLE may have a space in it, hence I need to output to be
"outputs": {
"ouput": {
"type": "String",
"value": "\n echo \"${USER}\"\n "
}
}
to prevent argument splitting.
So, I have tried to edit my template to include the quotes
/* example_template.json */
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"var": {
"type": "string",
"defaultValue": "
echo \"${VARIABLE}\"
",
"metadata": {
"description": "some description"
}
}
},
"resources": [],
"outputs": {
"ouput": {
"type": "string",
"value": "[string(parameters('var'))]"
}
}
}
Which gives me a validate and create error:
> az deployment group validate -f example_template.json -g resource-group-name
Failed to parse 'example_template.json', please check whether it is a valid JSON format
This seems to only happen with the multi-line string - if I put the whole defaultValue on a single line i.e.,
"defaultValue": "echo \"${VARIABLE}\""
it is successful again.
I need to use a multiline string as this variable is for a long deployment script which would be infeasible to put on one-line.
I believe this is a bug due to the parser only failing with the multiline string, but am unsure where to report it!
Does anyone know what a possible solution to this could be?
Thanks,
Akhil
Actually there is no significance to do multi-line manually like you did.
As you can see, the type of this "var" parameter is "string", so it should be a string in "defaultValue", thus the reason you got the error message. Even it worked without error when using PowerShell command like "New-AzDeployment" ,but the result is same.
As you want to "use a multiline string as this variable is for a long deployment script", you can try do this to make the defaultValue to be a string:
"parameters": {
"var": {
"type": "string",
"defaultValue": "VARIABLE={value1}\n echo \"${VARIABLE}\"",
"metadata": {
"description": "some description"
}
}
},
The output should be:
VARIABLE={value1}
echo "${VARIABLE}"
Actually az command is based on python, Power Shell command is based on c#, which made them parse json differently.
About how Azure CLI parse json, it starts reading defaultValue string with ", and cannot find the opposite " in the same line, then the error occurs.
About how Power Shell parse json, it starts reading defaultValue string with :, and read the whole content included in that :.
Deploy ARM template with Power Shell.
I'm working on ARM Templates. Actually, I have to deploy two resources at a time into my Azure account. For that, I used copyindex() concept with the help of following document and am able to deploy them successfully. Now am trying to display the names of deployed resources by using Output concept in ARM. But due to looping of resources deployment, its resulting in following error.
"DeploymentOutputEvaluationFailed",
"message": "Unable to evaluate template outputs: 'alertName'. Please see error details and deployment operations. Please see https://aka.ms/arm-debug for usage details.",
"details": [
{
"code": "DeploymentOutputEvaluationFailed",
"target": "alertName",
"message": "The template output 'alertName' is not valid: The language expression property 'alertMetricType' can't be evaluated.."
}
]
Could you please suggest me to "How to fetch the values of copyindex() looping as ARM Output session values"
I would suggest to reference it like this for example because you need to assemble anarray which you need to each of your template to take the output from the previous one and concat it with its own output then print the result.
"parameters": {
"state": {
"value": []
}
}
"parameters": {
"state": {
"value": "[reference(concat('loop', copyIndex())).outputs.state.value]"
}
}
then call it in output:
"outputs": {
"state": {
"type": "array",
"value": "[concat(parameters('state'), array(stuff_out))]"
}