The following error appears when trying to run the function: Unable to resolve the value for property 'CosmosDBAttribute.ConnectionStringSetting'. Make sure the setting exists and has a valid value.
That property exists both in the local.settings.json and in my Application Settings on Azure.
One important bit: It works on my machine now, but it didn't use to work. It started working out of nowhere even when I had not made any changes. It still doesn't work for others trying to run it on their machines.
Another important bit: They CAN get it to work by adding the attribute to their environment variables on their PC, but that is just a workaround.
I'm using Windows 10 and using Intellij as my IDE.
This is the code of the function I'm trying to run:
@FunctionName("postLogItem")
public HttpResponseMessage post(
@HttpTrigger(name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
@CosmosDBOutput(
name = "document",
databaseName = "AuditLog",
collectionName = "Logs",
connectionStringSetting = "CosmosDBAttribute.ConnectionStringSetting")
OutputBinding<String> document,
final ExecutionContext context) {
// Item list
context.getLogger().info("Parameters are: " + System.getenv("CosmosDBAttribute.ConnectionStringSetting"));
// Parse query parameter
String query = request.getQueryParameters().get("desc");
String name = request.getBody().orElse(query);
// Generate random ID
final int id = Math.abs(new Random().nextInt());
// Generate document
final String jsonDocument = "{\"id\":\"" + id + "\", " +
"\"description\": \"" + name + "\"}";
context.getLogger().info("Document to be saved: " + jsonDocument);
//LogItem item = new LogItem("123", "101010", "{'name':'potato'}", LogItem.TYPE.PAYMENT);
document.setValue(jsonDocument);
return request.createResponseBuilder(HttpStatus.OK)
.body("Document created successfully.")
.build();
}