将代码中所有的ES6的import语句改成require语句,并且在AWS Lambda函数的根目录下添加一个package.json文件,然后在该文件中添加"modules": "commonjs"配置项,示例代码如下:
//改写前 import AWS from 'aws-sdk';
exports.handler = async (event, context) => { //... };
//改写后 const AWS = require('aws-sdk');
exports.handler = async (event, context) => { //... };
//package.json { "name": "my-lambda-function", "version": "1.0.0", "description": "My Lambda function", "main": "index.js", "type": "module", "engines": { "node": "14.x" }, "dependencies": { "aws-sdk": "^2.965.0" }, "modules": "commonjs" }