Cheat Sheet: Azure SDKs

Series of short snippets of FUC. This one is for Azure SDKs.
August 21, 2018

I often find myself searching the internet for the same four lines of C# all over again, because of my inability to remember anything and the complexity of my filesystem structure… That’s why I decided to start putting together quick snippets of frequently used code (FUC).

This one is about various Azure SDKs I work with.

It’s a living document, I’ve been updating it over time.

Working with Storage Tables

There’s new NuGet library for working with Storage Tables - coming from the effort to unify traditional Tables and Cosmos DB Table API.

Do NOT use .NET Core - as of today (June 2nd) there’s no support with this newer library.


Install-Package Microsoft.Azure.DocumentDB
Install-Package Microsoft.Azure.Storage.Common –IncludePrerelease -Version
Install-Package Microsoft.Azure.CosmosDB.Table

Create table client:

var storageAccount = CloudStorageAccount.Parse("<connection string>");
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("<table name>");

List entities in partition:

var query = new TableQuery<MyEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "<pk>"));

IEnumerable<MyEntity> res = table.ExecuteQuery(query);

Get single entity:

TableOperation retrieveOperation = TableOperation.Retrieve<MyEntity>(partitionKey, rowKey);
TableResult retrievedResult = table.Execute(retrieveOperation);

if (retrievedResult.Result != null)
    // found
    // not found

Insert entity:

TableOperation insertOperation = TableOperation.Insert(entity1);

Replace entity:

TableOperation updateOperation = TableOperation.Replace(entity2);

Azure Functions - HTTP

To change route for a particular function, edit host.json:

    "http": {
      "routePrefix": "" // empty string removes the 'api' prefix

Then in function.json set route:

  "bindings": [
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
      "authLevel": "anonymous",
      "route": "myroute"

(Or do it in C# as the [HttpTrigger] attribute.)

Azure Resource Manager

A few quick and dirty snippets, since it’s impossible to remember everything when working with ARM.

Application Insights Instrumentation Key

Azure Functions provide native support for Application Insights telemetry, you only need to define the APPINSIGHTS_INSTRUMENTATIONKEY application setting and ARM provides the value:

"properties": {
    "siteConfig": {
        "appSettings": [
                "value": "[reference(parameters('insights_name')).InstrumentationKey]"

Cognitive Services keys


[listKeys(parameters('translator_name'), '2016-02-01-preview').key1]

Event Grid


[listKeys(parameters('transcript_grid_name'), '2018-01-01').key1]



[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storage_account_name'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storage_account_name')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]
comments powered by Disqus