1

How do we return data in Azure sync function app. Here is the code I have written to connect with azure key vault and capture secrets but it returns null result. And if I don't use context.done() then it goes for infinity run.

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;
}

Any Idea how can return the username?

1 Answer 1

1

You can try to do put snf_user in the response body instead of return like this:

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();
};

And then you can get the snf_user from the response body.:)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.