Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda async functions - unexpected token #158

Closed
tarasowski opened this issue Jul 17, 2018 · 3 comments
Closed

Lambda async functions - unexpected token #158

tarasowski opened this issue Jul 17, 2018 · 3 comments

Comments

@tarasowski
Copy link

Hi guys,

thank you for working on lambda-local. Just tried to run a following function:

module.exports.handler = async(event, context, callback) => {
    console.log(event)
    return 'Hello from Lambda'
}
$ lambda-local -l index.js -h handler -e examples/s3-put.js
warning Using both auth systems: aws_access_key/id and secret_access_token !
info: START RequestId: 995c192f-b25e-28c8-6579-0cee824da6f3
/home/ec2-user/environment/test/index.js:2
module.exports.handler = async(event, context, callback) => {
                              ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object._executeSync (/home/ec2-user/.nvm/versions/node/v6.14.3/lib/node_modules/lambda-local/lib/lambdalocal.js:157:26)
error: End - Error
error: ------
error: {
        "errorMessage": "Unexpected token (",
        "errorType": "SyntaxError",
        "stackTrace": [
                "ule.exports.handler = async(event, context, callback) => {",
                "",
                "",
                "taxError: Unexpected token (",
                "createScript (vm.js:56:10)",
                "Object.runInThisContext (vm.js:97:10)",
                "Module._compile (module.js:549:28)",
                "Object.Module._extensions..js (module.js:586:10)",
                "Module.load (module.js:494:32)",
                "tryModuleLoad (module.js:453:12)",
                "Function.Module._load (module.js:445:3)",
                "Module.require (module.js:504:17)",
                "require (internal/module.js:20:19)",
                "Object._executeSync (/home/ec2-user/.nvm/versions/node/v6.14.3/lib/node_modules/lambda-local/lib/lambdalocal.js:157:26)"
        ]
}
error: ------
error: Lambda failed in 18ms.
@gpotter2
Copy link
Collaborator

gpotter2 commented Jul 17, 2018

This is an issue with your function, you are wrongly declaring it (SyntaxError).

Have a look at https://stackoverflow.com/a/42964310/5459467

We have an example of a working async function in our tests https://github.com/ashiina/lambda-local/blob/develop/test/functs/test-func-async.js

@tarasowski
Copy link
Author

Yes, thank you! My node runtime was 6.xx on a new machine, haven't switched to 8.10.

@gpotter2
Copy link
Collaborator

Good ! Glad you fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants