简体   繁体   English

AWS Lambda Cloudwatch 规则

[英]AWS Lambda Cloudwatch Rule

I have created a CloudWatch Rule with the following event pattern:我创建了一个具有以下事件模式的 CloudWatch 规则:

{
  "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.这个想法是每次集群的状态发生变化时,它都会调用一个 lambda 函数。

Now, the problem is that when it invokes the lambda function, I get the following error:现在,问题是当它调用 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)

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?那么,我应该使用哪个类来解析 CloudWatch 规则事件?

Thank you.谢谢你。

You can listen to one of the event type in the documentation,您可以收听文档中的一种事件类型,

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

Rule is NOT an cloudwatch event.规则不是cloudwatch 事件。

Also you can define a dynamic object and get the details of the object that get sent to your Lambda.您还可以定义一个动态对象并获取发送到您的 Lambda 的对象的详细信息。

Hope it helps.希望能帮助到你。

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

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