Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Azure CLI Advance Debug

 

Azure CLI Advance Debug

Azure CLI is a powerful command-line interface that allows you to manage Azure resources and services. When working with the CLI, you may encounter issues or errors that require advanced debugging techniques to resolve. In this blog, we will explore some advanced debugging techniques that you can use to troubleshoot issues in Azure CLI. 

  • Use verbose mode

The Azure CLI has a verbose mode that can provide more detailed information about the commands that you run. By adding the "-v" or "--verbose" flag to your command, you can enable verbose mode and get more information about the command's execution. 

For example, to enable verbose mode when running the "az login" command, you can use the following command:

az login -v

This will provide more information about the authentication process and help you identify any issues that may be preventing you from logging in.  

  • Use the "--debug" flag

The Azure CLI also has a "--debug" flag that enables debug logging for a specific command. By using this flag, you can get more detailed information about a specific command's execution. 

For example, to enable debug logging for the "az storage blob upload" command, you can use the following command:

az storage blob upload --debug

This will provide more information about the upload process and help you identify any issues that may be preventing the upload from succeeding. 

  • Use the "az feedback" command

If you encounter an issue that you cannot resolve, you can use the "az feedback" command to report the issue to the Azure CLI team. This will provide them with more information about the issue and help them identify the cause.

 For example, to report an issue with the "az storage account create" command, you can use the following command:

 az feedback --cli az storage account create

This will open a web page where you can provide details about the issue, including any error messages that you received. 

In conclusion, when working with Azure CLI, there are several advanced debugging techniques that you can use to troubleshoot issues and resolve them quickly. By using verbose mode, enabling debug logging, using the "--debug" flag, and using the "az feedback" command, you can get more detailed information about the commands that you run and identify the cause of any issues that you encounter.

Azure Functions timeout

Azure Functions timeout

Everything about function app timeout

 

Issue:

·       Timeout value of 00:05:00 exceeded by function?

·       What is azure functions timeout?

·       What is azure functions execution timeout?

·       What is default timeout in azure function?

·       Consumption plan timeout?

·       Premium plan timeout?

 

Solution:

What is timeout?  In business logic language, a timeout is a specified period of time that will be allowed to complete an operation and if that operation doesn’t complete within specified period of time then it will throw some exception. Timeouts allow for more efficient usage of limited resources without requiring additional interaction from the agent interested in the goods that cause the consumption of these resources.

A common example is your smart phone turn off backlight after a certain time when idle which you can set.

Similarly, Azure has set the timeout for function app and it is very important to understand it as you can develop/write your business logic and optimize it accordingly.

In Azure functions, timeout means if your business logic or code should be optimized enough to complete with timeout duration otherwise it throws exception like “Timeout value of 00:05:00 exceeded by function”


In Azure functions, timeout varies according to hosting plan and runtime versions.

Azure functions have 3 hosting plans,

  • Consumption plan (Dynamic plan)
  • Premium plan (Elastic premium plan)
  • App Service plan (Dedicated plan
And as of now it has 3 runtime versions,

·       1.x

·       2.x

·       3.x

Where 1,2 and 3 is the major version and x stand for minor version e.g. 2.09234.

Now we know what azure functions execution timeout is? hence we should focus on

·       Default timeout,

·       maximum timeout

for each hosting plan.

You can check this information in the below list.

Azure Functions timeout











That means if you see exception like “Timeout value of 00:05:00 exceeded by function” then you quickly need to check if your function is hitting the default timeout.

Here you have 2 options,

1.      Investigate why your code execution is taking that much of time and optimize your code

2.      Increase the default timeout.

For first case you better know how to optimize the code.

How to modify the default timeout

Azure functions timeout value is stored and handled in host.json file and attribute name is functionTimeout

{

    "functionTimeout": "00:05:00"

}

 

functionTimeout indicated the timeout duration for all the functions and not for the single function.

You can update the default timeout value, save it, and test your function again.

In dedicated app service plan there is no limit but you should keep a fixed upper bound limit as unlimited timeout can have some disadvantages like your execution will keep executing and you will have to pay for it.

For unlimited timeout you can use -1

{

    "functionTimeout": "-1"

}

Important note

Regardless of the function app timeout setting, 230 seconds is the maximum amount of time that an HTTP triggered function can take to respond to a request. This is because of the default idle timeout of Azure Load Balancer. For longer processing times, consider using the Durable Functions async pattern or defer the actual work and return an immediate response.


Function timeout at function level

We know now that we can set function timeout in host.json but it is for all the function inside it. What about setting timeout for one or 2 function only.

While developing the functions from Visual Studio, you can now set the timeout at the function level.

Adding the attribute [Timeout("00:00:10")], above the function definition would set the timeout value for the function.  more details.

I did test the function executions to confirm that it doesn’t affect executions of other functions in the same function app.

With the test deployment I made – I deployed multiple function to the Function App on Azure, with only one of them (say function A) having the timeout set. While executing the functions, we see that A stops after the threshold timeout value and the others continue as expected.

Imp Note: This is for C# language only.

Azure Functions timeout


Output:

Azure functions timeout





Hope this helps. Please let me know if you have any query

References:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale

https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout


Azure apps/resources locks to prevent changes

Azure apps/resources locks to prevent changes

 

Issue:

·       How can I lock my azure apps so that others can’t update/modify it?

·       Read only azure resources are possible?

·       I want other member in my team should not be able to update my resources.

·       Prevent accidental changes.

 

Solution:

 

To be very frank, this is a valid ask from anyone. If I have a big team size but I want them to provide them only read-only access or they should not be able to delete anything.

 

The good news is, you don’t have to do much for this. Azure provides you this feature which just have to be enabled by you and this feature name is “LOCKS”.

 

You can check in below screen shot which is for Azure app service, but you can use it for any other azure resources,

Lock resources to prevent unexpected changes



Types of Lock

  •          ReadOnly
  •          CanNotDelete

ReadOnly lock means nobody can update or delete except then authorized users. You can relate this lock with Reader RBAC role.

CanNotDelete as names says you can not delete the resource but modify and read only.

 

Important Points

·       Locks can be applied at Subscription, resource group or at resource level.

·       If you apply locks at subscription level, then all resource within that will have same lock inherited

·       If you don’t want to apply lock at subscription level, then you can apply at individual resource also.

·       In a nutshell, parent resource lock is being inherited by child resources also.

·       Locks can be applied through other mechanism also like,

o   PowerShell

§  New-AzResourceLock

o   CLI

§  az lock

o   Rest API

§  PUT https://management.azure.com/{scope}/providers/Microsoft.Authorization/locks/{lock-name}?api-version={api-version}

o   ARM Template

 

How to apply lock from portal

Applying locks from the porta is the easiest approach.

You can refer below screen.

Step 1: Click on locks

Step 2: Click on Add

Step 3: Select Lock Type

Step 4: Provide lock name

Step 5: Provide some description in notes section like purpose of this lock

Step 6: Click on OK

And You are done.

Lock resources to prevent unexpected changes

 Hope this helps.

 

Please refer below URL for more details about Locks,

https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/lock-resources

 


Azure App Service FTP _ Azure app Service create/reset FTP user level credential through PowerShell


Azure app Service create/reset FTP user level credential through PowerShell




Issue:

·       How can I create FTP deployment credentials?

·       How to reset User credentials for azure app service?

·       I want to use PowerShell for this.

·       Can I get publish profile details through PowerShell?



Solution:

We all are aware that Azure app service content can be accessed through FTP.  This is one of the most easy and popular way to deploy your content to Azure app service.
When you create an app service or web app, Azure add an FTP hostname with that app. You can get the FTP hostname information in the “Overview” blade of your app service.




Here it is very important to understand that Azure app service support 2 types of credentials,
·       User Level credentials
·       App Level credentials

User level credentials are for entire Azure account which can be used to deploy to any web app for the subscription,

while App Level credentials are particular web app specific and can't be used with any other web app. App Level credentials are generate automatically at app creation. Users can’t control this manually.
Now question is, where can I check these credentials and answer is simple,
Go to “deployment center” blade and click on FTP.


Once you click on “dashboard” button, a new pop up window will appear with App and user level credentials.



You can see that App level credentials can only be reset but you don’t have control to define the username or password here.
You can control user level credentials. Here we have one catch; you can have only one FTP user level credential. You can’t have multiple FTP user level credentials.

Now, If you want to create/reset user level or app level credentials using PowerShell then answer is Yes it is possible.

Ø  Create or Reset User level credentials,

$properties = @{        publishingUserName = “<your user name>”;
 publishingPassword = “<your password>”
    }
Set-AzureRmResource -Properties $ properties -ResourceId /providers/Microsoft.Web/publishingUsers/web -ApiVersion 2015-08-01 -Force

# -ApiVersion : Specifies the version of the resource provider API to use. If you do not specify a version, this cmdlet uses the latest available version.

Ø  You can get the publish profile user details,

Invoke-AzureRmResourceAction -ResourceGroupName <resource group name> -ResourceType Microsoft.Web/sites/config -ResourceName <your site name>/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force

# -ApiVersion : Specifies the version of the resource provider API to use. If you do not specify a version, this cmdlet uses the latest available version.
#You can find credentials details in the properties

I hope this helps. Please comment if you have any query

Other useful FTP links,


Other useful references,

Issue: Azure function is throwing one of the following exceptions
·       Unable to retrieve Functions Keys
·       We are not able to retrieve the keys for function
·       The function runtime is unable to start.
·       Function host is not running.
·       Internal Server error.
·       Service Unavailable.

Issue: Azure Functions: The Consumption pricing tier is not allowed in this resource group


Issue: Disable Azure functions






Unable to edit/delete files through KUDU site (409 conflict: could not write to local resource)

Azure | Unable to edit/delete files through KUDU site(409 conflict: could not write to local resource)


Scenarios

Edit Error

When you open any file in KUDU and try to save after updating, you may get this error.

409 conflict: could not write to local resource

DELETE Error

 When you try to delete the same file, you may get below error.



These errors are confusing. For example when you try to delete any file and get an exception, “404 Not found” but actually file is available in Folder and visible

Solution

This issue is pertaining to Files permission. You can check the permission of any file using below command,

attrib FileName

e.g.

attrib index.html

When we run this command, we will get details of all permission applied on that file,



We can clearly see that this file has been marked as “Read Only” and can’t be modified or deleted.
               
Once we remove this read-only permission using below command then the user will be able to edit/delete the file.

attrib -r index.html

          you can run attrib -r *.* to do them all at once.

Similarly, there might be some other permissions which can play an important role here.


Attrib

Displays, sets, or removes the read-only, archive, system, and hidden attributes assigned to files or directories. Used without parameters, attrib displays attributes of all files in the current directory.

Syntax

attrib [{+r|-r}] [{+a|-a}] [{+s|-s}] [{+h|-h}] [[Drive:][Path] FileName] [/s[/d]]

Parameters

+r   : Sets the read-only file attribute.
-r : Clears the read-only file attribute.
+a : Sets the archive file attribute.
-a : Clears the archive file attribute.
+s : Sets the system file attribute.
-s : Clears the system file attribute.
+h : Sets the hidden file attribute.
-h : Clears the hidden file attribute.


Please refer below URL for the complete list of Attrib command.


You can also use below alternative,
·         FTP
·         App Service Editor
               
If all these steps doesn't resolve your issue then you can check below URL to understand how to deal with locked file in Azure App Service

https://github.com/projectkudu/kudu/wiki/Dealing-with-locked-files-during-deployment

I hope this is helpful. Please share your query/feedback.


Other useful references,

Issue: Azure function is throwing one of the following exceptions
·       Unable to retrieve Functions Keys
·       We are not able to retrieve the keys for function
·       The function runtime is unable to start.
·       Function host is not running.
·       Internal Server error.
·       Service Unavailable.


Issue: Azure Functions: The Consumption pricing tier is not allowed in this resource group



Issue: Disable Azure functions