How to delete Azure EventGrid topics? - azure

I created an EventGrid topic like this and chose the wrong location:
az eventgrid topic create --name esales -l eastus -g mylaketest
I then noticed I chose the wrong location so I tried to delete the topic with this command:
az eventgrid topic delete --name esales -g mylaketest
If I enter this command:
az eventgrid topic list
I get this response:
[]
So I assume the topic has been deleted.
If I correct my initial command and enter it again, this time with a different location:
az eventgrid topic create --name esales -l westeurope -g mylaketest
I get this response:
(ResourceConflict) Topic with name esales already exists. Choose a different topic name. For more troubleshooting information, please refer to https://aka.ms/EventGridTroubleshooting . Code: ResourceConflict Message: Topic with name esales already exists. Choose a different topic name. For more troubleshooting information, please refer to https://aka.ms/EventGridTroubleshooting .
Looks like I need to delete something else or I missed anything?

I tried to create an event grid topic according to your requirements and was able to successfully execute it with the same name in a new location once it was deleted.
Verify the following:
1. It takes much longer to delete an event grid topic than it does to create one. Wait for it to finish, otherwise it will throw the same error that you received.
2. In addition to your creation, if any other topic exists in any other resource group created by someone else, this error is thrown.
az eventgrid topic create -l EastUs:
az eventgrid topic create -g <ResourceGroup> --name mytopic -l EastUs
az eventgrid topic delete:
az eventgrid topic delete -g <ResourceGroup> --name mytopic
az eventgrid topic list:
az eventgrid topic list -g <ResourceGroup>
az eventgrid topic create -l westus2:
az eventgrid topic create -g <ResourceGroup> --name mytopic -l westus2
Refer MSDoc

Related

Cannot set functionAppScaleLimit setting in Azure CLI for Azure Function

I'm attempting to set the functionAppScaleLimit to 1 according to the documentation here:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale#limit-scale-out
Using the az resource update --resource-type Microsoft.Web/sites -g <resource_group> -n <function_app_name>/config/web --set properties.functionAppScaleLimit=<scale_limit> command appears like it's working, but if I look at the Azure Function app settings using az resource show --ids <subscription_id> the functionAppScaleLimit is set to null. After I do the update command, the output shows properties.functionAppScaleLimit is set to 1. However, when I check with az resource show the functionAppScaleLimit setting appears to be in properties.siteConfig.functionAppScaleLimit.
Why do the settings look different after the update and when I check with az resource show? If I try to update instead using --set properties.siteConfig.functionAppScaleLimit=1 I get an error. I'll be doing some testing to see if the setting is actually working, but this seems a little strange.
It seems the format of az resource show is different, sorry I didn't find the reason, but we can sure that we can do this command to limit scale out:
az resource update --resource-type Microsoft.Web/sites -g <resource_group> -n <function_app_name>/config/web --set properties.functionAppScaleLimit=<scale_limit>
for ensuring it works or not, better use portal or the command I post instead --ids option.
az resource show --resource-type Microsoft.Web/sites -g <ResourceGroup> -n <FunctionName>/config/web

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)
}

The attempt to validate the provided endpoint resource failed

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

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

Azure function app create

I´m using az functionapp create for creating function ap in Azure, where apparts of creating the function app it also hooks it to a bitbucket repo. I´m using parametere --deployment-source-url -u but it seems is not working this way and is giving me an error. This is done by a jenkin file pipeline
node {
stage('Azure Login') {
withCredentials([azureServicePrincipal('6-8afd-ae40e9cf1e74')]) {
sh 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'
sh 'az account set -s $AZURE_SUBSCRIPTION_ID'
}
}
stage('Build Azure FuntionApp') {
sh 'az functionapp create -g $RG_NAME -p $SP_NAME -n grey-$JOB_NAME-$BUILD_NUMBER -s $SA_NAME --deployment-source-url https:// bitbucket.org/xxxx/functions/s***strong text***rc/develop --debug'
}
If I put --deployment-source-url -u https://user#bitbucket.org I get:
ERROR: az functionapp create: error: argument
--deployment-source-url/-u: expected one argument
I tried without the -u just : --deployment-source-url https://#bitbucket.org
and the job gets done, but the link with bitbucket repos is not made. Getting this:
So how is it that this work? how come if I put user it says invalid argument and if I don´t it pases but It can find user. Does anyone ever used this command to create a function app? thanks!
If you want to create azure function via azure-cli, you could change the deployment resource url after --deployment-source-url. You could refer to my command to create a function with a blob trigger, replace the url of yours. It works fine on my side.
Note: The Access level should be public, you could check it in Settings like the screenshot below.
az functionapp create --deployment-source-url https://bitbucket.org/xxx/azure-function --resource-group resourcegroupname --consumption-plan-location westeurope --name joyfun22 --storage-account <storage_name>
Besides, you also can use a github repository to create a function.
For example, to use the command below to create a function with a blob trigger.
az functionapp create --deployment-source-url https://github.com/Joyw1/Azure-Function-Trigger --resource-group myResourceGroup --consumption-plan-location westeurope --name <app_name> --storage-account <storage_name>
Update:
If your Access level is private. You need a access token to access your bitbucket repository. Please follow the steps bellow.
1.Go to the Bitbucket Labs -> Access Management -> OAuth -> Add consumer
More details, refer to this link.
2.Enable authenticated git deployment with Azure CLI
#!/bin/bash
gitrepo=<Replace with your GitHub repo URL e.g. https://github.com/Azure-Samples/functions-quickstart.git>
token=<Replace with a GitHub access token>
# Enable authenticated git deployment
az functionapp deployment source update-token \
--git-token $token
For complete command, refer to this link.

Resources