Azure

How to downgrade the tier or SKU of an Azure resource

We were recently doing a POC for a customer where in we were using an Integration Account(Standard tier). As it wasn’t production scale we thought of downgrading the SKU to free tier but didn’t find any option to do so from the portal.

Fortunately, we can do the same using Azure CLI/Powershell. Here’s the CLI script we used to downgrade the Integration Account’s SKU to free tier:

az resource update --resource-group SourceAs2 --resource-type Microsoft.Logic/integrationAccounts --name Integrationaccount --subscription 860188f0-6i3c-911c-98e0-4dcc90a57c70 --set sku.name=Free

Lo and behold, the tier downgraded to free tier.

Standard
Azure, Cognitive services, Connected Field Service

Invalid subscription key error when connecting Azure cognitive services Face API

Recently during an integration scenario with D365 Field services in order to identify if the person making a change to the Customer asset is an employee or not we spinned up an Azure Face API service and on trying to connect it from an Azure function we were getting Invalid key exception.

We were using the Face API client library which defaults to west US endpoint of the service but our service was in EastUS.

Default endpoint: https://westus.api.cognitive.microsoft.com/face/v1.0/

The solution is to override the endpoint to https://eastus.api.cognitive.microsoft.com/face/v1.0/ which can be done by using another constructor of the FaceServiceClient class

FaceServiceAPIClient = new FaceServiceClient("Face API subscription key", "https://eastus.api.cognitive.microsoft.com/face/v1.0");

 

 

Standard
Azure, Azure IOTHub, Connected Field Service

Direct methods vs Cloud to Device messaging in Azure IOT Hub – When to use what?

Let’s see types of messages supported in Azure IOT Hub:

Cloud to Device messaging

Direct method

There are use cases for using each of these message types and one or the other isn’t  the solution for all problems.

Let’s see few of the differences between how these 2 methods work:

  • CDM uses One way messaging where as Direct method uses 2 way connection
  • Because of the above reason there is no easy feedback loop, there is a way to      leverage feedback endpoint in IOTHub but there is no way to relate feedback with message
  • CDM uses Hub to store the message and Hub is responsible of re-trying logic to send the message until expiration (configured at Hub level or can be configured for each device)
  • CDM Supports AMQP/ MQTT and HTTPS but Direct Methods don’t support HTTPS
Standard
Azure, Azure IOTHub, C#

Leveraging feedback endpoint in Azure IOT Hub

If you have played with Azure IOT Hub you might already know that there is an Azure Event hub endpoint behind the scene which takes care of message ingestion.

So your devices and backend applications use this endpoint for Cloud to device and Device to cloud communication.

In a scenario where the backend application wants to send a message to a Device and doesn’t care if the message was accepted/rejected or abandoned by the device then subscribing to the Event hub end point alone may do the trick.

But if you want feedback from IOT Hub that the message was indeed delivered and was it accepted or rejected you can subscribe to another already configured end point in Azure IOT hub which is the Feedback End point.

Let me show you the default endpoints configured in Azure IOT hub I just created:

6

If you see the above screenshot, there are 2 end points listed in IOT Hub:

  • Feedback
  • Events (Event Hub endpoint)

Now the next question is how to leverage this endpoint?

Fortunately Azure IOT Hub sdks have classes that take care of this, the class is called the FeedbackReceiver class and you can instantiate it using the ServiceClient object.

var feedbackReceiver = serviceClient.GetFeedbackReceiver();

Once you have the instance of this class, you can call the ReceiveAsyn() method to loop through the feedbacks to obtain the MessageId and the Status which could be one of the following:

  • Success
  • DeliveryCountExceeded
  • Expired
  • Rejected
  • Purged

Finally we can let the Hub know we are done processing feedbacks by calling the CompleteAsync() method.

 

As you see it’s not that hard to plug in the feedback loop for cloud to device messages 🙂

 

 

Standard
Azure, Azure IOTHub, Connected Field Service, Dynamics 365 Field Services, Logic Apps, Microsoft Dynamics 365

Get Device ConnectionString from IOTHub using LogicApp

As of today, there are 3 connectors to Azure IOT Hub:

5.JPG

I recently had a requirement to get the Device Connectionstring from IOTHub using DeviceId and IOT Hub connectionstring.

The solution comprised of following 2 items:

  1.  Custom connector to get Device Connectionstring
    1. This is a Web api deployed on Azure which has a Post method, takes in DeviceId and IOTHub connectionstring and returns Device Connectionstring using Azure IOTHub sdk.
    2.  HTTP + Swagger action was used in Logic app to consume this.
  2.  Logic app wrapper which was consumed by other apps.

If you want to use the Connector, consume the following swagger file:

https://getdeviceidconnector.azurewebsites.net/swagger/docs/v1

 

Here’s the logic app definition:

https://www.dropbox.com/s/cc86kk3co6wdmuv/GetIOTHubDeviceConnectionString.txt?dl=0

 

 

 

 

 

 

 

Standard
Azure, Azure ML

Azure ML Vs Cortana Intelligence Gallery

I lot of devs starting with Machine Learning go through this confusion of choosing between technologies offered by Azure.

What I have seen is Azure ML offers more control over building a Model hence if you understand regression/classification/categorization/Anomaly detection and able to decide when to use a Supervised/Un-Supervised/Reinforcement learning algorithm you should stick to Azure ML.

On the other hand, if you are looking for ready-made models/samples to quickly get running solutions go with Cortana Intelligence Gallery.

Standard
Azure, powershell

Copying Azure Appsettings between App services using powershell script

In a project lifecycle you are mostly dealing with a lot of servers, each representing a stage in your project cycle.

App services usually have app settings stored in Azure which makes it quite convenient for the admin to update them from Azure and not giving access to the values to a developer.

I always felt the pain of copying down appsettings from 1 App service to another on different servers so I wrote down this simple script which does the work for me.

 

 

$myResourceGroup = ‘RG-CRM-AE-PREPROD’

 

$mySite = ‘AT-CRM-UBIQUITY-AE-PP-01’

 

$webApp = Get-AzureRmWebApp -ResourceGroupName $myResourceGroup -Name $mySite

$appSettingList = $webApp.SiteConfig.AppSettings

 

$hash = @{}

ForEach ($kvp in $appSettingList) {

$hash[$kvp.Name] = $kvp.Value

}

 

$hash[‘NewKey’] = “NewValue”

$hash[‘ExistingKey’] = “NewValue”

 

Set-AzureRmWebApp -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $hash

 

Standard
Azure

Azure scheduler –Day light saving

There’s a very common problem of working with Azure schedulers when there is a day light saving in a particular time zone.

You end up starting/stopping the scheduler to adjust it’s time of running to make for the day light saving change.

There is a better solution for this problem by using Azure Automation service in which the scheduler can be configured to run in a particular time zone and it automatically takes care of the day light savings adjustments for you.

Here you can see how time zone can be configured while setting up a scheduler.

image

Standard
Azure, Uncategorized

How to deploy a Web Application to Azure using Powershell

I have been using this ps script to deploy a webapp/ webapi to Azure using Powershell. It has minimal configuration but the commands allow you to define everything from Resource Group to scaling options for that matter if there is a need.

  1. PS D:\Deploy> $WebSiteLoc=”East US”
  2. PS D:\Deploy> $WebSiteName = “PowershellTrialSaurabh”
  3. PS D:\Deploy> Test-AzureName -Website $WebSiteName
    False
  4. PS D:\Deploy> New-AzureWebsite -Location $WebSiteLoc -Name $WebSiteName

Instances : {}
NumberOfWorkers : 1
DefaultDocuments : {Default.htm, Default.html, Default.asp, index.htm…}
NetFrameworkVersion : v4.0
PhpVersion : 5.4
RequestTracingEnabled : False
HttpLoggingEnabled : False
DetailedErrorLoggingEnabled : False
PublishingUsername : $PowershellTrialSaurabh
PublishingPassword : EFWilNQrGDMoeYh1oemrku0NSn47h2P8SiPgPDaulebANQzlefzz0qFLTppQ
AppSettings : {WEBSITE_NODE_DEFAULT_VERSION}
Metadata : {}
ConnectionStrings : {}
HandlerMappings : {}
Name : PowershellTrialSaurabh
State : Running
HostNames : {powershelltrialsaurabh.azurewebsites.net}
WebSpace : saurabhfirstmvcsample-RG-EastUSwebspace
SelfLink : https://waws-prod-blu-053.api.azurewebsites.windows.net:454/subscriptions/a866dc2f-b0
ec-4247-80d2-80a365738118/webspaces/saurabhfirstmvcsample-RG-EastUSwebspace/sites/Pow
ershellTrialSaurabh
RepositorySiteName : PowershellTrialSaurabh
Sku : Free
UsageState : Normal
Enabled : True
AdminEnabled : True
EnabledHostNames : {powershelltrialsaurabh.azurewebsites.net,
powershelltrialsaurabh.scm.azurewebsites.net}
SiteProperties : Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.SitePropertie
s
AvailabilityState : Normal
HostNameSslStates : {powershelltrialsaurabh.azurewebsites.net,
powershelltrialsaurabh.scm.azurewebsites.net}
AzureDriveTraceEnabled :
AzureDriveTraceLevel : Error
AzureTableTraceEnabled :
AzureTableTraceLevel : Error
AzureBlobTraceEnabled :
AzureBlobTraceLevel : Error
ManagedPipelineMode : Integrated
WebSocketsEnabled : False
RemoteDebuggingEnabled : False
RemoteDebuggingVersion :
RoutingRules : {}
Use32BitWorkerProcess : True
AutoSwapSlotName :
SlotStickyAppSettingNames : {}
SlotStickyConnectionStringNames : {}

6. PS D:\Deploy> Show-AzureWebsite $WebSiteName
7. PS D:\Deploy> $path = “D:\Deploy\sampleazureapp.zip”
8. PS D:\Deploy> Publish-AzureWebsiteProject -Name $WebSiteName -Package $path
Change Summary:
Bytes Copied: 23380708
Files Added: 108
Files Updated: 4
Files Deleted: 1
Errors: 0
Warnings: 0
Parameters Changed: 0
Total No of Changes: 113

Standard
Azure, C#

Azure Webjob not starting – Status Pending Restart

Recently I have been working with WebJobs and one common issue while deploying these is getting a Pending Restart status on the Azure Portal.

Pending Restart basically means there was an error/exception while Azure tried to run your Job.

First of all check your Webjob logs and see the exception being thrown:

Now go back and check for the code you have written in your WebJob and see if something needs to be fixed.

 

Issue for me was related to configuration. There are 3 important configuration settings you need in your webjob config file:

  1. ServiceBus Connectionstring (Connectionstribf to your ASB namespace)
  2. AzureWebJobsDashboard (This would come from Azure storage A/C you want to use to store the logs from the job)
  3. AzureWebJobsStorage (same as above)

 

Final words

Webjobs are a great way to do background processing/ supporting async operations/ reading or writing to Queues and should be leveraged whenever there’s a use case for them.

 

Standard