我正在尝试将由Blob存储触发的Azure函数“退出”到Cosmos db。但是Cosmos db是否具有Cassandra Api或连接字符串? 我需要SQL api吗?
function.json
{ "scriptFile": "__init__.py", "bindings": [
{
"name": "inputBlob",
"type": "blobTrigger",
"direction": "in",
"path": "myblobcontainer/input/{name}",
"connection": "AzureWebJobsStorage"
},
{
"direction": "out",
"type": "cosmosDB",
"name": "$return",
"databaseName": "solar_system",
"collectionName": "mercury",
"leaseCollectionName": "leases",
"createLeaseCollectionIfNotExists": true,
"connectionStringSetting": "AzureWebJobsDocumentDBConnectionString",
"createIfNotExists": false
} ] }
初始化 .py
import logging
import azure.functions as func
import json
def main(inputBlob: func.InputStream) -> func.Document:
logging.info(f"Blob trigger executed with cosmo {inputBlob.name} >>>")
logging.info(f"Blob Name: {inputBlob.name} ({inputBlob.length}) bytes")
logging.info(f"Full Blob URI: {inputBlob.uri}")
# for testing purpose, the below data dictonary is inserted.
newdoc_dict = {
"area":1234,
"name":"mmmmm",
"tim":1234567890,
"info":"bbbb"
}
newdocs = (func.Document.from_dict(newdoc_dict))
return newdocs
在
“ connectionStringSetting”:“ AzureWebJobsDocumentDBConnectionString”
,AzureWebJobsDocumentDBConnectionString设置为我的cosmos db cassandra API
Exception type Microsoft.Azure.WebJobs.Host.FunctionInvocationException
Exception message Exception while executing function: Functions.cosmo <--- Invalid URI: The format of the URI could not be determined.
InvocationId bb7f698b-e162-4f5b-844a-75f0349c755a
FormattedMessage Executed 'Functions.cosmo' (Failed, Id=bb7f698b-e162-4f5b-844a-75f0349c755a)
LogLevel Error
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.cosmo ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.Config.CosmosDBConnectionString..ctor(String connectionString) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Config\CosmosDBConnectionString.cs:line 32
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBService..ctor(String connectionString, ConnectionPolicy connectionPolicy) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Services\CosmosDBService.cs:line 20
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.DefaultCosmosDBServiceFactory.CreateService(String connectionString, ConnectionPolicy connectionPolicy) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Config\DefaultCosmosDBServiceFactory.cs:line 12
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBExtensionConfigProvider.<>c__DisplayClass14_0.<GetService>b__0(String c) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Config\CosmosDBExtensionConfigProvider.cs:line 131
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBExtensionConfigProvider.GetService(String connectionString, String preferredLocations, Boolean useMultipleWriteLocations) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Config\CosmosDBExtensionConfigProvider.cs:line 131
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBExtensionConfigProvider.CreateContext(CosmosDBAttribute attribute) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Config\CosmosDBExtensionConfigProvider.cs:line 138
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.Bindings.CosmosDBCollectorBuilder`1.Convert(CosmosDBAttribute attribute) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.CosmosDB\Bindings\CosmosDBCollectorBuilder.cs:line 17
at Microsoft.Azure.WebJobs.Host.Bindings.PatternMatcher.Invoker`2.<>c__DisplayClass0_0.<Execute>b__0(Object input, Attribute attr, ValueBindingContext ctx) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\PatternMatcher.cs:line 365
at Microsoft.Azure.WebJobs.Host.Bindings.AsyncCollectorBindingProvider`2.ExactBinding`1.BuildAsync(TAttribute attrResolved, ValueBindingContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\BindingProviders\AsyncCollectorBindingProvider.cs:line 353
at Microsoft.Azure.WebJobs.Host.Bindings.BindingBase`1.BindAsync(BindingContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\BindingBase.cs:line 50
at Microsoft.Azure.WebJobs.Binder.BindAsync[TValue](Attribute[] attributes, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\Runtime\Binder.cs:line 108
at Microsoft.Azure.WebJobs.Script.Binding.FunctionBinding.BindAsyncCollectorAsync[T](BindingContext context) in /azure-functions-host-47c594d8ba823cf5a2db5475fbfcbb6d83e7deca/src/WebJobs.Script/Binding/FunctionBinding.cs:line 145
at Microsoft.Azure.WebJobs.Script.Binding.ExtensionBinding.BindAsync(BindingContext context) in /azure-functions-host-47c594d8ba823cf5a2db5475fbfcbb6d83e7deca/src/WebJobs.Script/Binding/ExtensionBinding.cs:line 55
at Microsoft.Azure.WebJobs.Script.Description.WorkerLanguageInvoker.<>c__DisplayClass10_0.<<BindOutputsAsync>b__0>d.MoveNext() in /azure-functions-host-47c594d8ba823cf5a2db5475fbfcbb6d83e7deca/src/WebJobs.Script/Description/Rpc/WorkerLanguageInvoker.cs:line 139
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.WebJobs.Script.Description.WorkerLanguageInvoker.BindOutputsAsync(Object input, Binder binder, ScriptInvocationResult result) in /azure-functions-host-47c594d8ba823cf5a2db5475fbfcbb6d83e7deca/src/WebJobs.Script/Description/Rpc/WorkerLanguageInvoker.cs:line 143
at Microsoft.Azure.WebJobs.Script.Description.WorkerLanguageInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /azure-functions-host-47c594d8ba823cf5a2db5475fbfcbb6d83e7deca/src/WebJobs.Script/Description/Rpc/WorkerLanguageInvoker.cs:line 81
at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /azure-functions-host-47c594d8ba823cf5a2db5475fbfcbb6d83e7deca/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 85
at Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidTaskMethodInvoker.cs:line 20
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 584
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 531
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, IFunctionOutputDefinition outputDefinition, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 467
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 277
--- End of inner exception stack trace ---
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 321