AWS Lambda Cloudwatch规则

时间:2017-10-18 14:09:02

标签: java amazon-web-services aws-lambda aws-sdk

我创建了一个包含以下事件模式的CloudWatch规则:

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

这个想法是每次集群状态发生变化时,都会调用lambda函数。

现在,问题是当它调用lambda函数时,我收到以下错误:

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)

使用代码:

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";
    }
}

那么,我应该使用哪个类来解析CloudWatch Rule事件?

谢谢。

1 个答案:

答案 0 :(得分:1)

您可以在文档中收听其中一个类型

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

规则是一个cloudwatch事件。

您还可以定义动态对象并获取发送给Lambda的对象的详细信息。

希望它有所帮助。