4
votes

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?

1
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
I tried that but somehow they don't work out of the box like they do in the sample app (github.com/Azure-Samples/…) 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
Try using the Premium Storage SDK, and not the Azure Storage SDK.Matias Quaranta
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
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

1 Answers

1
votes

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