使用AWSCLI的AWS Lambda日志:如何使用AWSCLI访问Lambda日志? [英] AWS Lambda Logs using AWSCLI: How can I access Lambda logs using AWSCLI?
问题描述
我试图在ubuntu ec2实例上使用awscli使用AWS Lambda,但是我无法访问aws控制台.请注意,我没有使用无服务器或zapper,而是直接将我的main.py文件以及相关文件压缩为此处
I was trying to work with AWS Lambda using the awscli on an ubuntu ec2 instance, and I do not have access to the aws console. Note that I am not using serverless or zapper, I directly zip my main.py file along with the dependency files as mentioned here
我这样运行函数
aws lambda invoke --function-name python-test --invocation-type RequestResponse outfile.txt
输出文件中给出的错误非常模糊,在调试时无济于事,反而使我更加困惑.使用管理员的系统,我可以在控制台上运行测试时识别错误,但是如何使用awscli检查这些日志?
The errors given in the outfile are very vague and dont help in debugging, rather they confuse me more. Using the admin's system, I am able to recognize the errors when I run a test on the console, but How can I check those logs using the awscli ?
所以我尝试运行aws cloudwatch list-metrics > cloudwatch_logs.log
并在cloudwatch_logs.log文件中搜索功能名称"python-test",我可以找到此功能的Namespace
,MetricName
,Dimensions
,但是如何访问日志?
So I tried running aws cloudwatch list-metrics > cloudwatch_logs.log
and searching the function name 'python-test' in the cloudwatch_logs.log file, I am able to find Namespace
, MetricName
, Dimensions
for this function, but how do you access the logs ?
任何与相似示例链接的帮助都非常感谢!
Any help with links to similar examples greatly appreciated !
推荐答案
首先,获取日志组名称:
aws logs describe-log-groups --query logGroups[*].logGroupName
[
"/aws/lambda/MyFunction"
]
然后,列出该日志组的日志流:
Then, list the log streams for that log group:
aws logs describe-log-streams --log-group-name '/aws/lambda/MyFunction' --query logStreams[*].logStreamName
[
"2018/02/07/[$LATEST]140c61ffd59442b7b8405dc91d708fdc"
]
最后,获取该流的日志事件:
aws logs get-log-events --log-group-name '/aws/lambda/MyFunction' --log-stream-name '2018/02/07/[$LATEST]140c61ffd59442b7b8405dc91d708fdc'
{
"nextForwardToken": "f/33851760153448034063427449515194237355552440866456338433",
"events": [
{
"ingestionTime": 1517965421523,
"timestamp": 1517965421526,
"message": "START RequestId: bca9c478-0ba2-11e8-81db-4bccfc644168 Version: $LATEST\n"
},
{
"ingestionTime": 1517965424581,
"timestamp": 1517965424567,
"message": "END RequestId: bca9c478-0ba2-11e8-81db-4bccfc644168\n"
},
{
"ingestionTime": 1517965424581,
"timestamp": 1517965424567,
"message": "REPORT RequestId: bca9c478-0ba2-11e8-81db-4bccfc644168\tDuration: 3055.39 ms\tBilled Duration: 3100 ms \tMemory Size: 128 MB\tMax Memory Used: 35 MB\t\n"
}
],
"nextBackwardToken": "b/33851760085631457914695824538087252860391482425578356736"
}
这篇关于使用AWSCLI的AWS Lambda日志:如何使用AWSCLI访问Lambda日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!