Try the following:
- Enable the managed identity for the Function App
- Go to your Azure Function in the portal.
- Identity → System assigned → Status: On → Save.
- This creates a principal in Entra ID that you can grant the Cosmos DB role to.
- If you’re using a User-assigned managed identity, make sure it exists and is attached to the Function App.
- Assign the role at the correct scope
- Navigate to your Cosmos DB account in the Azure portal.
- Access control (IAM) → Add role assignment.
- In Role, search for Cosmos DB Built-in Data Contributor.
- Assign access to → Managed identity → Select your Function App.
- Confirm the API type supports RBAC
- RBAC roles like Built-in Data Contributor are supported for SQL API, Mongo API (vCore), and certain other APIs, but not all features in all API types support it.
- For unsupported APIs, you’ll need to use keys instead of RBAC.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin