0
votes

I'm attempting to run the @azure/cosmos samples inside a node.js Azure Function. When it connects to the database it throws this error

" Executed 'Functions.store' (Failed, Id=a6df6cfb-ae78-4a0b-ae83-5d51efa9fc18) [10/7/2018 9:04:18 PM] System.Private.CoreLib: Exception while executing function: Functions.store. Microsoft.Azure.WebJobs.Host: Unable to resolve the value for property 'CosmosDBAttribute.ConnectionStringSetting'. Make sure the setting exists and has a valid value.

It fails at await client.databases.createIfNotExists

Anyone get @azure/cosmos to connect inside the index.js of an azure function?

Thanks, Donnie

const client = new CosmosClient({
  endpoint: endpoint,
  auth: { masterKey: masterKey }
});

async function init() {

  const database = await client.databases.createIfNotExists({
    id: databaseId
  });

  const container = await database.containers.createIfNotExists({
    id: containerId
  });

  return container;
}

edited: added connection info

const connection = {
  endpoint: "https://pdf-documents.documents.azure.com:443/",
  primaryKey:
  "Gub9FZeIMXwz6Lakn..."
};

const cosmos = require("@azure/cosmos");
const CosmosClient = cosmos.CosmosClient;
const endpoint = connection.endpoint;
const masterKey = connection.primaryKey;
const databaseId = "pdfDocuments";
const containerId = "pdfdocuments";

const client = new CosmosClient({
  endpoint: endpoint,
  auth: { masterKey: masterKey }
});
1
What does the endpoint value look like?Nick Chapsas
It appears to be looking for an entry in function.json for a binding and connection string in app settings. However, I'm connecting to the database from within the index.js file, where you enter the connection info there in the code.Donnie Kerr
added connection infoDonnie Kerr

1 Answers

1
votes

Thanks to Twitter @Ealsur for solving this for me! Even thought the error occurred in the debugger right at the moment it tried to connect to database, the error was actually an error related to another connection in the output binding of my function!

@azure/cosmos is working well inside an Azure Function.

Thanks again @Ealsur!