2
votes

I have created a CloudWatch Rule with the following event pattern:

{
  "detail-type": [
    "EMR Cluster State Change"
  ],
  "source": [
    "aws.emr"
  ]
}

The idea is that every time the state of the cluster changes, it invokes a lambda function.

Now, the problem is that when it invokes the lambda function, I get the following error:

An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: java.io.UncheckedIOException: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "state": com.amazonaws.services.cloudwatchevents.model.Rule#setState(1 params) vs com.amazonaws.services.cloudwatchevents.model.Rule#setState(1 params)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "state": com.amazonaws.services.cloudwatchevents.model.Rule#setState(1 params) vs com.amazonaws.services.cloudwatchevents.model.Rule#setState(1 params)

With code:

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.cloudwatchevents.model.Rule;

public class ErrorLambda implements RequestHandler<Rule, String>  {

    private static final Logger LOG = Logger.getLogger(ErrorLambda.class);

    public String handleRequest(Rule input, Context context) {
         LOG.info("Rule is " + input);
         return "Ok";
    }
}

So, which Class am I supposed to use to parse the CloudWatch Rule events?

Thank you.

1

1 Answers

1
votes

You can listen to one of the event type in the documentation,

http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html

Rule is NOT an cloudwatch event.

Also you can define a dynamic object and get the details of the object that get sent to your Lambda.

Hope it helps.