From f22bf256eaa326c8a4fd197226b3bc84c11c0af2 Mon Sep 17 00:00:00 2001 From: Jose Guadalupe Omar Ramirez Mata Date: Tue, 24 Oct 2023 19:15:32 -0600 Subject: [PATCH] Update index.js to prevent lambda aws error When you upload the last code lambda function send this error: Response { "errorType": "ReferenceError", "errorMessage": "exports is not defined in ES module scope", "trace": [ "ReferenceError: exports is not defined in ES module scope", " at file:///var/task/index.mjs:4:1", " at ModuleJob.run (node:internal/modules/esm/module_job:194:25)" ] } I modified the code to prevent the error in lambda tests. --- creating-a-lambda-function-using-the-aws-console/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/creating-a-lambda-function-using-the-aws-console/index.js b/creating-a-lambda-function-using-the-aws-console/index.js index 126c01f..63236c5 100644 --- a/creating-a-lambda-function-using-the-aws-console/index.js +++ b/creating-a-lambda-function-using-the-aws-console/index.js @@ -1,10 +1,10 @@ -const https = require('https') +import https from 'https' let url = "https://www.amazon.com" -exports.handler = function(event, context, callback) { +export const handler = function(event, context, callback) { https.get(url, (res) => { callback(null, res.statusCode) }).on('error', (e) => { callback(Error(e)) }) -} \ No newline at end of file +}