简体   繁体   English

如何从 aws lambda 调用中获取完整日志?

[英]How do I get full logs out of aws lambda invoke?

First, Cloudwatch logs aren't working for this function.首先,Cloudwatch 日志不适用于此功能。 Just get a message about how it failed to create a log stream.只需获取有关创建日志流失败的消息。 But I'm not sure that would help because when I invoke the function:但我不确定这会有所帮助,因为当我调用该函数时:

aws lambda invoke --function-name update-data out \
--payload '{"year": "2013"}' --log-type Tail \
--query 'LogResult' --output text |  base64 -D

The stack trace is pretty worthless:堆栈跟踪非常没有价值:

2019-06-30T23:17:31.684Z    undefined   ERROR   Uncaught Exception
{"errorType":"Runtime.UserCodeSyntaxError",
"errorMessage":"SyntaxError: Unexpected identifier","stack":
["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected identifier","

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:36:30)","
at Module._compile (internal/modules/cjs/loader.js:701:30)","
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)","
at Module.load (internal/modules/cjs/loader.js:600:32)","
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)","
at Function.Module._load (internal/modules/cjs/loader.js:531:3)","
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)","
at startup (internal/bootstrap/node.js:283:19)"]}

[mild edits for readability]

The function is running in Node 10. I have a suspicion regarding the actual issue but it would be really helpful in the future if I could figure out a better way to get to the source of the failure.该函数在 Node 10 中运行。我对实际问题有所怀疑,但如果我能找出更好的方法来找出故障的根源,这在将来会非常有帮助。

Is there a way to get to the source of the Unexpected identifier error?有没有办法找到Unexpected identifier错误的来源? Line # and file in my code that caused that error?导致该错误的代码中的第 # 行和文件?

我有一个类似的问题,我的问题最终是在我的项目不支持时导入使用 ESM 的包。

I had a similar issue with AWS amplify function.我对 AWS 放大功能有类似的问题。

My problem caused by import syntax(ES2015).我的问题是由导入语法(ES2015)引起的。 I use require syntax(node) instead of import syntax.我使用 require 语法(节点)而不是导入语法。 And it works.它有效。

SyntaxError: Unexpected identifier","stack":

Says that the error is in your function code.说错误在你的函数代码中。 Your using the "identifier" stack and it hadn't been declared mabe?您使用了“标识符”堆栈,但尚未声明为 mabe?

I've never used AWS lambda but, Runtime.UserCodeSyntaxError, sounds like the function encountered a runtime error ( during code execution ) related to the syntax of your code.我从未使用过 AWS lambda,但是,Runtime.UserCodeSyntaxError,听起来该函数遇到了与代码语法相关的运行时错误(在代码执行期间)。

I didn't have experience with Python.我没有使用 Python 的经验。 But I had it with Java.但我用 Java 实现了它。 In Java lambda function, I catch any exceptions and use e.printstackTrace() in the catch.在 Java lambda 函数中,我捕获任何异常并在捕获中使用 e.printstackTrace()。 The output goes to CloudWatch automatically输出自动转到 CloudWatch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM