How can I import AWS Pinpoint in a Lambda index.js file

15 Views Asked by At

Recently I upgraded to Lambda Node.js 18.x. As part of that I was told, the correct way to get access to Pinpoint is by using the following statements in my index.js file.

import { Pinpoint } from '@aws-sdk/client-pinpoint'; const pinpoint = new Pinpoint({ region: 'us-east-1' });

I am doing all this from Lambda console in AWS. When I test, I get the following Execution result.

Response { "errorType": "Runtime.UserCodeSyntaxError", "errorMessage": "SyntaxError: Cannot use import statement outside a module", "trace": [ "Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module", " 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" ] }

How can I fix this?

0

There are 0 best solutions below