Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Cloud9 AWS Lambda中的意外令牌函数_Amazon Web Services_Aws Lambda_Aws Cloud9 - Fatal编程技术网

Amazon web services Cloud9 AWS Lambda中的意外令牌函数

Amazon web services Cloud9 AWS Lambda中的意外令牌函数,amazon-web-services,aws-lambda,aws-cloud9,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

我正在节点为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);
 }

如何解决此问题?

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

nvm install 11
nvm use 11
nvm alias default v11

删除单词
函数