AWS Lambda - CloudWatch Event type

你说的曾经没有我的故事 提交于 2019-12-03 22:20:51

com.amazonaws.services.lambda.runtime.events.ScheduledEvent is the current answer.

I can see that in 2.0.2 version of aws-lambda-java-events library this is available. Code is here and more details on 2.0 version are here

Following is the boilerplate code for it.

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.ScheduledEvent;


public class CollectionLambda {
    public void eventHandler(ScheduledEvent event, Context context) {
        // todo
    }
}

Add following dependencies for maven:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-lambda-java-core</artifactId>
    <version>1.2.0</version>
</dependency>

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-lambda-java-events</artifactId>
    <version>2.2.2</version>
</dependency>

Unfortunately there is no specific class for this type of events.

But you can freely create your own POJOs and specify them as class of event parameter. For instance, CloudWatchEvent can be described as:

public class CloudWatchEvent {

    private String version;
    private String id;
    private String detailType;
    private String source;
    private String account;
    private Date time;
    private String region;
    private List<String> resources;
    ...   
    // getters and setters
}

AWS Lambda engine automatically tries to serialize input into the object of the given class.

To know the structure you can specify type "Map" and printout it to log:

  public void eventHandler(Map event, Context context) {
        log.debug(event); // or System.out....
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!