'Trouble with "Is not a function" error in NodeJS Lambda

I know there are several similar questions in StackOverflow, but the solutions on those did not help me here.

I am trying to use the aws-jwt-verify package in a lambda to verify a JWT token issued by AWS Cognito.

Here is how I am using the package

const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient();
const CognitoJwtVerifier = require("aws-jwt-verify");

exports.handler = async (event) => {
    console.log(CognitoJwtVerifier); // <-- returns { JwtRsaVerifier: [Getter], CognitoJwtVerifier: [Getter] }
    const verifier = CognitoJwtVerifier.create({
        userPoolId: "test",
        tokenUse: "access",
        clientId: "Test" ,
    });
    try {
        const payload = await verifier.verify(event.jwtToken);
        console.log("Token is valid. Payload:", payload);
    }catch {
        console.log("Token not valid!");
    }
}

When I run that, I get this error:

CognitoJwtVerifier.create is not a function

I had a look at the package, and I can definitely see a method called create in the there.

console.log(CognitoJwtVerifier); returns a value, so I know the package in imported into the lamdba.

Question: Why am I getting a "Is not a function" error, when create is defiantly a function in the aws-jwt-verify package



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source