I am using Twilio Messaging with AWS Lambda running on nodejs22.x x64 runtime to send SMS.
All the import
ing 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
Looks like it finally worked. I appended Twilio with
.default
So
This should be clarified in Twilio docs
It seems you figured it out. But this one should also work and looks maybe a bit cleaner: