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".
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.
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?
Also posted on the AWS forum: 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. After changin the resource to * the lambda function was able to create the log resource.
{
"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": "*"
}
]
}