Understanding Lambda Decision Errors for Phone Numbers Registered in DynamoDB

Asked 1 years ago, Updated 1 years ago, 364 views

Regarding the reference error below, I think there is something missing, but I can't find out what is missing.
Thank you for your cooperation.

Error Contents

"errorType": "ReferenceError",
"errorMessage": "require is not defined in ES module scope, you can use import installed",

Lambda Code

const AWS=require("aws-sdk");
const DynamoDB = new AWS.DynamoDB.DocumentClient({region: "ap-northeast-1"});
constableName = 'PhoneNumberTable';

exports.handler=async(event)=>{
// Caller ID
constphone=event.Details.ContactData.CustomerEndpoint.Address;
// Retrieving DynamoDB Listing
const db = wait DynamoDB.scan({TableName:tableName}).promise();
// Determining if Caller ID is in the List
const result=db.Items.some(item=>{
return (item.PhoneNumber==phone);
});
return { result:result};
};

aws aws-lambda amazon-dynamodb

2022-11-25 04:11

1 Answers

Judging from the error message, the code seems to be treated as an ES Module, so if you want to write using require, you need to have CommonJS handle it.

The file name of the code may be index.mjs, so try changing it to index.js.


2022-11-25 06:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.