如何从 Nodejs 中的同步 Azure 函数获得 return 结果
How to return results from the synhcronous Azure Function in Nodejs
我们如何return Azure 同步功能应用程序中的数据。这是我编写的用于连接 Azure Key Vault 并捕获机密的代码,但它 return 的结果为空。如果我不使用 context.done() 那么它会无限大 运行.
module.exports = function (context, req) {
var responseMessage = "starting Execution"
//Capturing the Credentials from the Azure Key vault for the snowflake
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const keyVaultName = "someKVname";
const KVUri = "https://" + keyVaultName + ".vault.azure.net";
const credential = new DefaultAzureCredential();
const client = new SecretClient(KVUri, credential);
let snowflake_username = async function(client){
const usr_retrievedSecret = await client.getSecret("username");
return usr_retrievedSecret.value;
};
var snf_user = snowflake_username();
context.log(snf_user);
context.done();
return snf_user;
}
知道如何 return 用户名吗?
您可以尝试将 snf_user
放入响应正文而不是 return
,如下所示:
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
//..........
function snowflake_username(){
//..............
return 111;
}
var snf_user = snowflake_username();
context.log(snf_user);
context.res = {
body: snf_user
};
context.done();
};
然后您可以从响应正文中获取 snf_user。:)
我们如何return Azure 同步功能应用程序中的数据。这是我编写的用于连接 Azure Key Vault 并捕获机密的代码,但它 return 的结果为空。如果我不使用 context.done() 那么它会无限大 运行.
module.exports = function (context, req) {
var responseMessage = "starting Execution"
//Capturing the Credentials from the Azure Key vault for the snowflake
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const keyVaultName = "someKVname";
const KVUri = "https://" + keyVaultName + ".vault.azure.net";
const credential = new DefaultAzureCredential();
const client = new SecretClient(KVUri, credential);
let snowflake_username = async function(client){
const usr_retrievedSecret = await client.getSecret("username");
return usr_retrievedSecret.value;
};
var snf_user = snowflake_username();
context.log(snf_user);
context.done();
return snf_user;
}
知道如何 return 用户名吗?
您可以尝试将 snf_user
放入响应正文而不是 return
,如下所示:
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
//..........
function snowflake_username(){
//..............
return 111;
}
var snf_user = snowflake_username();
context.log(snf_user);
context.res = {
body: snf_user
};
context.done();
};
然后您可以从响应正文中获取 snf_user。:)