Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.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
Javascript &引用;Runtime.UserCodeSyntaxError“;在尝试声明异步AWS Lambda函数时_Javascript_Node.js_Amazon Web Services_Aws Lambda_Async Await - Fatal编程技术网

Javascript &引用;Runtime.UserCodeSyntaxError“;在尝试声明异步AWS Lambda函数时

Javascript &引用;Runtime.UserCodeSyntaxError“;在尝试声明异步AWS Lambda函数时,javascript,node.js,amazon-web-services,aws-lambda,async-await,Javascript,Node.js,Amazon Web Services,Aws Lambda,Async Await,我有一个旧的AWS Lambda函数,它被声明为synchronous(使用承诺),声明如下: exports.getSong = (event, context, callback) => { } 它按预期工作。最近,我决定使用async/await重新编写它,并因此尝试异步声明getSong函数,如下所示: exports.getSong = async (event, context) => { } var anotherAsyncFunction = async () =

我有一个旧的AWS Lambda函数,它被声明为synchronous(使用承诺),声明如下:

exports.getSong = (event, context, callback) => { }
它按预期工作。最近,我决定使用async/await重新编写它,并因此尝试异步声明
getSong
函数,如下所示:

exports.getSong = async (event, context) => { }
var anotherAsyncFunction = async () => { }
exports.getSong = (event, context, callback) => { anotherAsyncFunction() }
    
在尝试执行时,我得到了以下全部错误:

{
  "errorType": "Runtime.UserCodeSyntaxError",
  "errorMessage": "SyntaxError: Unexpected token '.'",
  "trace": [
    "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '.'",
    "    at _loadUserApp (/var/runtime/UserFunction.js:98:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1133:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)",
    "    at Module.load (internal/modules/cjs/loader.js:977:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:877:14)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)",
    "    at internal/main/run_main_module.js:18:47"
  ]
}

但是,我得到了同样的错误。显然,它与Lambda中的异步函数声明有关。这里可能有什么问题?谢谢。

我遇到了类似的问题。对我来说,这是
res.Body?.toString('utf-8')
,lambda无法理解什么是
Body?
,我认为在您的情况下,您应该执行以下操作:

export const getSong = async (event, context) => { ...}

同样对于有相同问题的人,找出原因的最好方法是转到lambda代码页,它应该在代码行上显示一个红色的
X

看起来您需要添加更多代码供我们调试(即在第98行附近)。我没有98行代码。这就是为什么我说错误消息没有帮助。上面的代码是lambda的唯一代码吗?代码底部的
getSong
函数不是异步的…您希望使用wait处理
另一个异步函数
,还是打算使用
。然后
回调