The attempt to validate the provided endpoint resource failed - azure

Trying to create a new azure eventgrid endpoint subscription based on the code in the Microsoft tutorial here errors:
az eventgrid event-subscription create --source-resource-id $topicid --name eventsubscriptionname --endpoint-type storagequeue --endpoint $queueid --expiration-date "2020-05-15"
Deployment failed. Correlation ID: xxxx. The attempt to validate the provided azure endpoint resource:xxxx failed.
The tutorial says to ensure the account has write access to the storage, which it does, I am the owner. All properties in the command have valid values and I am executing from the azure cli.
What could I be doing wrong?

That's weird... I tried on my side and I have the expected result using the following commands :
$resourcegroup="your resource group"
$storagename="your storage name"
$queuename="your queue name"
$topicname="your topic name"
$subscriptionname="your subscription name"
$storageid=az storage account show --name $storagename --resource-group $resourcegroup --query id --output tsv
$queueid="$storageid/queueservices/default/queues/$queuename"
$topicid=az eventgrid topic show --name $topicname -g $resourcegroup --query id --output tsv
az eventgrid event-subscription create --source-resource-id $topicid --name $subscriptionname --endpoint-type storagequeue --endpoint $queueid --expiration-date "2020-05-15"
I sued PowerShell version 5.1.18362.752 and AZ CLI version 2.5.1

Related

Azure Cli - How to show API's operation backend (HTTPs endpoint) infos

I'm trying to display the backend base-url info of an operation's API in my apim instance, i can achieve my goal with the Azure Powershell Module command:
Get-AzApiManagementPolicy -Context $mycontextvar -ApiId "myapiid" -OperationId "myoperationid" -Subscription "mysub" | Select-Xml -XPath '/policies/inbound/set-backend-service' | ForEach-Object { $_.Node."base-url" }
However, i want to display it with an azure cli command. I tried with
az apim api operation list --api-id myapiid --resource-group myrg --service-name myservname --subscription mysub
and
az apim api list --resource-group myrg --service-name myservname --subscription mysub
without results.
I should take into consideration the az policy or the az network commands but i don't know how to start to use them to retrieve this info and, once i saw the documentation, i don’t even know if they can help me.
'
Which Azure CLI command should i use to gather the backend base-url?
What you can do until the GET policy operation is available in CLI:
get operation id / URL with az apim api operation show --api-id myapi --operation-id myop -g myrg -n myapim
you will see an id like "id": "/subscriptions/12345678-1234-5678-90ab-cdef12345678/resourceGroups/myrg/providers/Microsoft.ApiManagement/service/myapim/apis/myapi/operations/myop",
mix with policy GET operation https://learn.microsoft.com/en-us/rest/api/apimanagement/2019-12-01/api-operation-policy/get into
az rest --method get --url "https://management.azure.com/subscriptions/12345678-1234-5678-90ab-cdef12345678/resourceGroups/myrg/providers/Microsoft.ApiManagement/service/myapim/apis/myapi/operations/myop/policies/policy?api-version=2019-12-01"
which should give you the policy.

Updating EventGrid Topic to set DeadLettering destination using Azure CLI

I'm following the instructions here to add a --deadletter-endpoint to an existing EventGrid subscription.
The process is failing with error: Event subscription doesn't exist.
What am I missing?:
Azure Cloud Shell
Commands executed:
containername=eg-dead-letter-events //container where deadlettered events will be stored
topicid=$(az eventgrid system-topic show --name egtop-dev -g TEST_DEV --query id --output tsv) //name of eventgrid system topic
storageid=$(az storage account show --name stgdev --resource-group TEST_DEV --query id --output tsv) //name of storage account where deadlettered events will be stored
az eventgrid event-subscription update \
--name egsub-dev \ //name of Event Subscription here? also tried System Topic name, no go.
--source-resource-id $topicid \ //I cannot find a clear reference for what is supposed to go here
--deadletter-endpoint $storageid/blobServices/default/containers/$containername
Results: Event subscription doesn't exist.
Edit 1: Made some progress
This command helped list out the needed pieces:
az eventgrid event-subscription list --topic-type "Microsoft.Storage.StorageAccounts" --location southcentralus
Hardcoded values found in the above response as:
az eventgrid event-subscription update --name egsub-dev --source-resource-id /subscriptions/$subscription/resourceGroups/$resourceGroup/providers/Microsoft.Storage/storageAccounts/storageAccountThatTriggersEventGrid/providers/Microsoft.EventGrid/eventSubscriptions/egsub-dev --deadletter-endpoint $storageid/blobServices/default/containers/$containername
But this results in a different error:
No registered resource provider found for location 'southcentralus' and API version '2020-10-15-preview' for type 'storageAccounts'. The supported api-versions are '2021-04-01, 2021-02-01, 2021-01-01, 2020-08-01-preview, 2019-06-01, 2019-04-01, 2018-11-01, 2018-07-01, 2018-03-01-preview, 2018-02-01, 2017-10-01, 2017-06-01, 2016-12-01, 2016-05-01, 2016-01-01, 2015-06-15, 2015-05-01-preview'. The supported locations are 'eastus, eastus2, westus, westeurope, eastasia, southeastasia, japaneast, japanwest, northcentralus, southcentralus, centralus, northeurope, brazilsouth, australiaeast, australiasoutheast, southindia, centralindia, westindia, canadaeast, canadacentral, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, australiacentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast, westus3, jioindiawest'.
Thoughts on this one?
Regarding the issue, please update the script as below
sourceid=$(az eventgrid system-topic show --name egtop-dev -g TEST_DEV --query source --output tsv)
storageid=$(az storage account show --name stgdev --resource-group TEST_DEV --query id --output tsv)
az eventgrid event-subscription update \
--name egsub-dev \
--source-resource-id $sourceid\
--deadletter-endpoint $storageid/blobServices/default/containers/$containername

What is the right way to get Azure Cognitive service account endpoint from Azure-CLI

I was using the following command
$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query endpoint --output tsv)
but I found out that this stopped working when I ran this on another machine with a slightly newer version of Azure-CLI.
The JSON returned by the az cognitiveservices account show command is not consistent and looks like it has changed from version to a version.
How can I reliably get this not having to worry about the version of Azure CLI on the machine that I'm running on?
Or is there a completely different way to get the endpoint value?
With the newest version you will find endpoint in properties and since you rely on CLI version installed on the given machine you can simply modify your code to something like this:
$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query endpoint --output tsv)
if( !$cogVisionEndpoint ) {
$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query "properties.endpoint" --output tsv)
}

How to check if an azure resource is already in use using azure CLI?

Let's assume that an azure resource, ex "storage account" is being updated!
at the same time if I run a command like
az storage account update --default-action Allow --name MyStorageAccount --resource-group MyResourceGroup
It will throw an error
The request failed due to conflict with a concurrent request or something similar
So before running such command, how can I check if the resource is being used like being updated using Azure CLI
You could use az resource show to show everything about an Azure resource.
So in your case you would do:
az resource show -n "RESOURCE_NAME" -g "RESOURCE_GROUP" --resource-type "RESOURCE_TYPE"
I found the what I'm looking for inspired by the above answer at this link az resource wait
So it will be something like
az resource wait -n "RESOURCE_NAME" -g "RESOURCE_GROUP" --resource-type "RESOURCE_TYPE" --updated

Showing error when trying to start backup of vms through cli commands

I wrote the command:
az backup protection backup-now --resource-group Rsrgrp \
--vault-name CLIbkvault --container-name CLIcont \
--item-name MyItem --retain-until 29-02-2020 \
--backup-management-type AzureStorage
And I'm gettnig this error:
Item not found. Please provide a valid item_name.
I dont know which item name the error is referring to.
My guess this is the first time you try to backup the resource, is that so?
If so, you will need to first add the resource as protected to the backup vault, then the item name will be the name of the resource you are backing up.
Azure VM
az backup protection enable-for-vm --policy-name
--vm
[--disk-list-setting {exclude, include}]
[--diskslist]
[--ids]
[--resource-group]
[--subscription]
[--vault-name]
Azure File Share
az backup protection enable-for-azurefileshare --azure-file-share
--policy-name
--storage-account
[--ids]
[--resource-group]
[--subscription]
[--vault-name]
Azure Workload
az backup protection enable-for-azurewl --policy-name
--protectable-item-name
--protectable-item-type {HANAInstance, SAPHanaDatabase, SAPHanaSystem, SQLAG, SQLDatabase, SQLInstance}
--server-name
--workload-type {AzureFileShare, MSSQL, SAPHANA, SAPHanaDatabase, SQLDataBase, VM}
[--ids]
[--resource-group]
[--subscription]
[--vault-name]
https://learn.microsoft.com/en-us/cli/azure/backup/protection

Resources