- Le plus récent
- Le plus de votes
- La plupart des commentaires
First of all, please do not use JS V2 and Lambda Node runtime 16, you will be forced to change your entire function in a number of weeks.
As for your error, you are trying to import the package as a module, which it is not. Changing the extension forces it to be treated like a module, and that is why it works. For some strange reason you cannot change the extension, so you must change how you import the package. Use require()
rather than import
.
https://www.freecodecamp.org/news/how-to-use-the-javascript-require-function/
Thanks I will take care of using versions correctly,
If I use require() instead of import this error is thrown at runtime: require is not defined in ES module scope, you can use import instead.
Please you can take a look at my code snipet: https://gist.github.com/sandoval0992/157d0bd18465d987573abd2ab3f6de99
Hi,
As other colleagues suggest, I recommend using a more recent version of the Node.js runtime, and thus avoid problems in the short-medium term.
Take a look at the following example for Node.js 20.x Lambda runtime:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);
export const handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
};
You can find more examples on the AWS documentation.
Contenus pertinents
- demandé il y a 4 mois
- demandé il y a 2 ans
- AWS OFFICIELA mis à jour il y a 2 ans
- AWS OFFICIELA mis à jour il y a 2 ans
- AWS OFFICIELA mis à jour il y a 9 mois
- AWS OFFICIELA mis à jour il y a 7 mois
Hi,
I'm sorry to hear that. Would be possible to you attaching the index.js file content?
Hi @Mikel Del Tio, I just updated question to include lambda handler :)