Nodejs okta lib in lambda give inconsistent result


I am trying to use the okta nodejs library(@okta/jwt-verifier) to create a lambda authorizer in aws for apigw API. The code looks like below just as shown in the example. Similar code in local implemented as express app works fine. but when I put in a lambda function. for the same valid token and code, It sometimes validate the token correctly and goes into the “.then” block, meaning its valid. Sometimes, after call verifyAccessToken, it will not go in either .then block or the .catch block. So then not sure if the token is valid or not. The assumption is it should either go to the .then block or go to the .catch block. For the output which is a Promise. Is there any reason why it doesn’t fall in to either the .then or .catch block? Has the okta nodejs library been tested working in lambda function?

oktaJwtVerifier.verifyAccessToken(token, ‘api://default’)
.then(jwt => {console.log(‘token is valid’);

     console.log('claim: ',;
     .catch(err => console.warn('token failed validation'));

Thanks in advance.

Are you referring the function in the below link?

According to the doc, the expected audience passed to verifyAccessToken() is required.
Do you have the audience passed to the function?

Yes. audience is passed. audience is the 2nd parameter.
oktaJwtVerifier.verifyAccessToken(token, ‘api://default’)

The resolution is below in case anyone has this issue/need:
try {
let jwt = await oktaJwtVerifier.verifyAccessToken(token, ‘api://default’);
console.log(‘token is valid’);
} catch(err) {
console.warn(‘token failed validation’))