1
votes

In Azure, I have a javascript HTTPTrigger Function App with:

const azure = require('azure-storage')
const tableSvc = azure.createTableService(
    process.env.COSMOS_TABLE_ACCOUNT,
    process.env.COSMOS_TABLE_KEY,
    process.env.COSMOS_TABLE_ENDPOINT
)
const entGen = azure.TableUtilities.entityGenerator
const testData = {
    PartitionKey: entGen.String('test'),
    RowKey: entGen.String(1),
    name: entGen.String('It works!')
}

const insertTestData = () => new Promise((resolve, reject) => {
    tableSvc.insertEntity('tests', testData, (error, res) => {
        if (error) return reject(error)
        resolve(res)
    })
})
...

I've confirmed that the environment variables are all set and populated with the values from Azure Cosmos DB -> Cosmos Table Instance -> Connection String.

I've also tried connecting with:

const tableSvc = azure.createTableService(
    process.env.COSMOS_TABLE_CONNECTION_STRING
)

When I call insertTestData(), I'm getting back an error back from the .insertEntity callback with an empty object: {}. No entities are being added to my tests table, as confirmed by the Data Explorer.

Any ideas how to perform this operation or get more information in my debugger? I have an Insight monitor attached to the process, but it reports a successful completion.

1

1 Answers

2
votes

I noticed that you're passing a numeric value for RowKey attribute.

RowKey: entGen.String(1)

When I used the code, it complained about that.

When I changed the code to:

RowKey: entGen.String('1')

I was able to insert the entity.

Here's my complete code:

const azure = require('azure-storage')

const tableSvc = azure.createTableService(
    'account-name',
    'account-key',
    'https://account-name.table.core.windows.net'
)
const entGen = azure.TableUtilities.entityGenerator
const testData = {
    PartitionKey: entGen.String('test'),
    RowKey: entGen.String('1'),
    name: entGen.String('It works!')
}

console.log(testData);

const insertTestData = () => new Promise((resolve, reject) => {
    tableSvc.insertEntity('test', testData, (error, res) => {
        if (error) return reject(error)
        resolve(res)
    })
})

console.log('----------------');

insertTestData()
.then((result) => {
  console.log('result');
  console.log(result);
})
.catch((error) => {
  console.log('error');
  console.log(error);
})

I used azure-storage NPM package (version 2.10.2).