skip to Main Content

I am using Twilio Messaging with AWS Lambda running on nodejs22.x x64 runtime to send SMS.

All the importing looks fine (using lambda layer to import Twilio v5.4.1). But on execution, the lambda throws an error of Twilio is not a function when inputing credentials to a function which it is

Here is my lambda:

import * as Twilio from "twilio";

const twilioClient = Twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);

export const handler = (event, context) => {
...
};

I have also added type: "module" in my package.json

What can possibly be wrong here?

2

Answers


  1. Chosen as BEST ANSWER

    Looks like it finally worked. I appended Twilio with .default

    So

    const twilioClient = Twilio.default(AccountSid, AuthToken);
    

    This should be clarified in Twilio docs


  2. It seems you figured it out. But this one should also work and looks maybe a bit cleaner:

    import twilio from "twilio";
    
    const twilioClient = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search