I'm new to AWS lambda and am using nodejs v20 and am trying to write a very simple lambda at the moment:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand, GetCommand } from "@aws-sdk/lib-dynamodb";
import { https } from "https";
export const handler = async (event, context, callback) => {
// 1. Make an https.request() method call based on data in “event”
// 2. Based on the result, log something to DynamoDB
// 3. Reply to client with result
const response = {
statusCode: 200,
body: "..." };
return response;
};
The line import { https } from "https";
seems to be causing the below error. I also tried using const https = require('https');
and also const https = require('nodejs:https');
but I get the exact same error:
2024-04-29T06:19:51.669Z undefined ERROR Uncaught Exception
{
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Unexpected token '*'",
"stack": [
"Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '*'",
" at _loadUserApp (file:///var/runtime/index.mjs:1084:17)",
" at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
" at async start (file:///var/runtime/index.mjs:1282:23)",
" at async file:///var/runtime/index.mjs:1288:1"
]
}
Mind that I have not even written any code, I'm not able to import the https library to make the query to begin with. If I comment out this line, then the lambda runs with no issues. Would greatly appreciate some guidance in how I can import the https library so I can make an https.request() function call.