阅读背景:

从Java使用AWS Lambda进行日志记录似乎已被破坏

来源:互联网 

I have created the same function in Python and Java (simple hello world) following the guide. Using the same role the Python version works as expected generating the log stream entry and printing "ok".

我按照指南在Python和Java(简单的hello world)中创建了相同的函数。使用相同的角色,Python版本按预期工作,生成日志流条目并打印“ok”。

from __future__ import print_function
import json
print('Loading function')
def lambda_handler(event, context):
    return "ok"

However the Java version does not log anything with the same role and settings.

但是,Java版本不会记录具有相同角色和设置的任何内容。

package com.streambright;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class Dbmgmt implements RequestHandler<Object, Object> {
    @Override
    public String handleRequest(Object in, Context ctx) {
        System.out.println("test");
        ctx.getLogger().log("o hai");
        return "ok";
    }
}

I am wondering why it does not put anything into CloudWatch Log Groups. Does anybody have the same experience with Java? Does anybody have the same experience? Is there a fix workaround for this?

我想知道为什么它没有把任何东西放到CloudWatch Log Groups中。有没有人有相同的Java经验?有没有人有同样的经历?这有解决方法吗?

Also posted on the AWS forum: https://forums.aws.amazon.com/thread.jspa?threadID=254747

也发布在AWS论坛:https://forums.aws.amazon.com/thread.jspa?threadID = 254747

1 个解决方案

#1


1  

Found the root cause of this. The role policy was not allowing the correct log resource to be created, and it silently failed. The AWS UI was not too helpful to help identify this issue, I was running into it accidentally during an audit. After changin the resource to * the lambda function was able to create the log resource.

找到了这个的根本原因。角色策略不允许创建正确的日志资源,并且它以静默方式失败。 AWS UI对于帮助识别此问题并没有太大帮助,我在审核期间意外地遇到了这个问题。在将资源改为*之后,lambda函数能够创建日志资源。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "xray:PutTraceSegments",
                "xray:PutTelemetryRecords",
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "ec2:CreateNetworkInterface",
                "ec2:DeleteNetworkInterface",
                "ec2:DescribeNetworkInterfaces",
                "kms:Decrypt"
            ],
            "Resource": "*"
        }
    ]
}

分享到: