4

I'm trying to use Cosmos DB table API from an Azure function. Using the local.settings.json file I'm able to read the connection string and parse it successfully as I'm used to:

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=MYSTORAGEACCOUNT;AccountKey=AUTHKEY;TableEndpoint=https://COSMODB.documents.azure.com"
   }
}

Initiating connection:

var storageAccount = CloudStorageAccount.Parse(ConnectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("users");

The problem comes after this when I call

table.CreateIfNotExists();

This returns a http error 400 with the inner exception also being a http error 400 and no further explanation. It seems looking at the Cosmos DB sample that I need to set some additional settings, probably atleast this:

<configuration>
   <appSettings>
     <!--Table creation options -->
     <add key="TableThroughput" value="700"/>
   </appSettings>
</configuration>

How do I go about setting these either in code or in the local.settings.json file so I can use them in the Azure function? Or am I heading the wrong direction?

Kim Lindqvist
  • 363
  • 4
  • 15
  • To add an app setting, just add another node under `Values`. Have you tried to use Table binding instead? (I haven't, so not sure if it works with Cosmos) – Mikhail Shilkov Sep 17 '17 at 15:28
  • I tried that but somehow they don't work out of the box like they do in the sample app (https://github.com/Azure-Samples/azure-cosmos-db-table-dotnet-getting-started) with the App.config. Everything works fine if I use regular table storage with a connection string but it seems I'm missing something regarding the Cosmos table API. I'll have a look into table bindings for Cosmos. – Kim Lindqvist Sep 17 '17 at 15:33
  • Try using the [Premium Storage SDK](https://www.nuget.org/packages/WindowsAzure.Storage-PremiumTable/), and not the Azure Storage SDK. – Matias Quaranta Sep 18 '17 at 10:15
  • This error comes from Premium Storage SDK. I was able to get the bindings working for both graph API and document DB using the function.json definitions but still no luck with the table API. – Kim Lindqvist Sep 18 '17 at 13:28
  • How are you wiring up the Premium Storage SDK? I'm wondering if perhaps you're still using the Azure Storage SDK b/c that's what's being referenced by the Functions host. Can you add a line like: `trace.LogInformation($"Assembly: {table.GetType().Assembly.FullName}");` to your code and see what assembly your table is coming from? – brettsam Sep 18 '17 at 15:41

1 Answers1

1

We do not currently support talking to Table API from Azure Functions. It is on our road map.

Yaron Y. Goland
  • 756
  • 6
  • 15