SyntaxError in Step Functions Tutorial

0

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

Moe
asked a year ago1555 views
2 Answers
0

Please check the following:

  1. Your node,js version is 16.x
  2. Your index file has an extension of mjs as you are using ES module syntax - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html
AWS
answered a year ago
  • 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

0

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:

Screenshot:

Moe
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions