1

I have a typical NodeJS Azure Function App with a Function inside, generated by the func standard CLI in Typescript.

The function has a default structure:

const httpTrigger: AzureFunction = async function (context: Context,
    req: HttpRequest): Promise<void> {
...
   const mySecret = await secretClient.getSecret(mySecretName);
...
}

Now, every call of a handler triggers a call to KeyVault that looks very slow and red on my Application Map. Therefore I am looking into moving secret readout to the section before the trigger. It would allow, in my understanding, that if function is warm, then trigger will spend no time li getting secrets again and again. (I stress this is my guess but not a hard fact as I am not entirely familiar with Function App lifecycle).

How can I correctly implement logic "do this async initialization of a Function and allow calling trigger only after it is fully completed"?

1 Answer 1

2

If your Azure fn app runs at least Node v14.8.0, you can simply use top-level await :)

const mySecret = await secretClient.getSecret(mySecretName);

const httpTrigger: AzureFunction = async function (
    context: Context,
    req: HttpRequest
): Promise<void> {
...

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