Cloud9 AWS Lambda中的意外令牌功能

时间:2018-07-12 09:30:46

标签: amazon-web-services aws-lambda aws-cloud9

我正在尝试在带有节点v8.11.3 npm v5.10.0的AWS lambda函数中使用异步/等待方法。运行时,它会给出以下响应:

{
    "errorMessage": "Unexpected token function",
    "errorType": "SyntaxError",
    "stackTrace": [
        "                        ^^^^^^^^",
        "SyntaxError: Unexpected token function",
        "createScript (vm.js:56:10)",
        "Object.runInThisContext (vm.js:97:10)",
        "Module._compile (module.js:542:28)",
        "Object.Module._extensions..js (module.js:579:10)",
        "Module.load (module.js:487:32)",
        "tryModuleLoad (module.js:446:12)",
        "Function.Module._load (module.js:438:3)",
        "Module.require (module.js:497:17)",
        "require (internal/module.js:20:19)"
    ]
}

lambda函数为:

const fetch = require('node-fetch')
exports.handler = async function(event,context)
{
 console.log(event);

 let img = await 
 fetch(`https://catappapi.herokuapp.com/users/${event.userId}`);
 let parseddata = await img.json()
 console.log(parseddata.imageUrl);
 }

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

您收到此错误,是因为您在cloud9环境进程中运行了旧版的nodejs(可以通过console.log(process.version)进行验证,该版本与node --version不同)。请按照以下步骤更新Cloud9环境中的流程节点:

nvm install 11
nvm use 11
nvm alias default v11