[Azure Function Isolated] Cosmos change feed listener tries to start before CreateContainerIfNotExistsAsync
See original GitHub issueFor isolated azure functions, I believe that the cosmos change feed tries to listen before containers have been created. Either that or I’m doing something wrong?
Thanks
Setup:
Program.cs
var host = new HostBuilder()
...
.Build()
var client = host.Services.GetRequiredService<CosmosClient>();
var databaseResponse = await client.CreateDatabaseIfNotExistsAsync(Configuration["DbName"]);
var database = databaseResponse.Database;
await database.CreateContainerIfNotExistsAsync("container", "/id");
host.Run();
Function.cs
[Function("DoSomething")]
public async Task Run(
[CosmosDBTrigger("%DbName%", "container",
ConnectionStringSetting = "CosmosDbConnectionString",
LeaseCollectionName = "leases",
CreateLeaseCollectionIfNotExists = true)] IReadOnlyList<Entity> input)
{
}
Error message on local machine:
The listener for function ‘DoSomething’ was unable to start. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Either the source collection ‘container’ (in database ‘db’) or the lease collection ‘leases’ (in database ‘db’) does not exist. Both collections must exist before the listener starts. To automatically create the lease collection, set ‘CreateLeaseCollectionIfNotExists’ to ‘true’
Versions
Microsoft.Azure.Functions.Worker.Sdk 1.3.0 Microsoft.Azure.Functions.Worker.Extensions.Http 3.0.13 Microsoft.Azure.Cosmos 3.26.1 Microsoft.Azure.Functions.Worker.Extensions.CosmosDB 3.0.9
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Closing as out of the scope of this repo. https://github.com/Azure/azure-functions-host might be a good candidate to ask how you can execute code before the runtime loads the declared Functions.
@andersson09 - Correct, but that error message is just the Extension saying that it cannot find the container, it has nothing to do with your intent to create the container before the Function is initialized. The Extensions start when the Host/Runtime tell them to start, they do not have control over when that happens.
What is happening is that you have some code that you want to run before the Host signals the Extensions to start, but you are not able to put that code in a place where the Host is executing it before. The Host is starting the Extensions either at the same time or before your code.
In order to know where to put your code to achieve what you want, you need guidance or at least someone that knows how the Function Host works. This is not the repo.