Hi there,
I'm doing this tutorial: https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-get-started-create-first-sm.html
There I need to create a Lambda Function in Node.js 16.x, this code has been provided:
export const handler = async function(event, context) {
const credLimit = Math.floor(Math.random() * 10000);
return (credLimit);
};
When I test the code I get the following result though:
{
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Unexpected token 'export'",
"trace": [
"Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token 'export'",
" at _loadUserApp (file:///var/runtime/index.mjs:993:17)",
" at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1031:21)",
" at async start (file:///var/runtime/index.mjs:1194:23)",
" at async file:///var/runtime/index.mjs:1200:1"
]
}
This is the first function in the state machine this tutorial is about. This error appears also when I execture the state machine of course.
I am quite a newbie and don't know how to proceed...can someone help me please?
Thanks in advance!
Best
Moe
Thanks Mike,
regarding 1): Yes, thats correct regarding 2): It has indeed been a .js file (this is the default index after selecting 16.x though...)
I've changed the name to index.mjs but the test still throws an error:
Response { "errorType": "Runtime.UserCodeSyntaxError", "errorMessage": "SyntaxError: Unexpected token 'export'", "trace": [ "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token 'export'", " at _loadUserApp (file:///var/runtime/index.mjs:993:17)", " at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1031:21)", " at async start (file:///var/runtime/index.mjs:1194:23)", " at async file:///var/runtime/index.mjs:1200:1" ] }
Function Logs 2023-03-21T12:45:45.106Z undefined ERROR Uncaught Exception {"errorType":"Runtime.UserCodeSyntaxError","errorMessage":"SyntaxError: Unexpected token 'export'","stack":["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token 'export'"," at _loadUserApp (file:///var/runtime/index.mjs:993:17)"," at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1031:21)"," at async start (file:///var/runtime/index.mjs:1194:23)"," at async file:///var/runtime/index.mjs:1200:1"]} 2023-03-21T12:47:11.303Z undefined ERROR Uncaught Exception {"errorType":"Runtime.UserCodeSyntaxError","errorMessage":"SyntaxError: Unexpected token 'export'","stack":["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token 'export'"," at