简体   繁体   English

从Java使用AWS Lambda记录似乎已损坏

[英]Logging with AWS Lambda from Java seems to be broken

I have created the same function in Python and Java (simple hello world) following the guide. 我已经按照指南在Python和Java(简单的hello world)中创建了相同的函数。 Using the same role the Python version works as expected generating the log stream entry and printing "ok". 使用相同的角色,Python版本将按预期工作,生成日志流条目并打印“确定”。

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. 我想知道为什么它没有将任何内容放入CloudWatch Log Groups。 Does anybody have the same experience with Java? 是否有人对Java有相同的经验? Does anybody have the same experience? 有人有同样的经历吗? Is there a fix workaround for this? 是否有解决此问题的解决方法?

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

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. AWS UI不太有助于识别此问题,我在审核期间偶然遇到了该问题。 After changin the resource to * the lambda function was able to create the log resource. 将资源更改为*之后,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": "*"
        }
    ]
}

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

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