AWS Lambda - CloudWatch 事件类型 [英] AWS Lambda - CloudWatch Event type

查看:29
本文介绍了AWS Lambda - CloudWatch 事件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写由 Cloudwatch 计划事件触发的 AWS Java Lambda 函数时,哪个事件对象会被传递给 Lambda 处理程序函数?

When writing an AWS Java Lambda function that's triggered by Cloudwatch scheduled events, which event object gets passed to the Lambda handler function?

例如,对于由 S3 事件触发的 Lambda 函数,AWS 会调用该函数并传递一个 S3Event 对象.同样,它会将 SNSEvent 对象传递给由 SNS 消息触发的函数.

For example, for a Lambda function triggered by an S3 event, AWS invokes the function and passes an S3Event object. Similarly, it would pass an SNSEvent object to a function triggered by an SNS message.

public class LambdaHandler {

    public void eventHandler(S3Event event, Context context) {
    }

public class LambdaHandler {

    public void eventHandler(SNSEvent event, Context context) {
    }

对于 Cloudwatch Scheduled Event 驱动的函数,什么可以代替 SNSEvent/S3Event?

For a Cloudwatch Scheduled Event driven function, what would be in place of SNSEvent / S3Event?

public class LambdaHandler {

    public void eventHandler(__________ event, Context context) {
    }

我一生都找不到任何由 Cloudwatch 计划事件触发的用 Java 编写的 AWS Lambda 函数示例...

I can't for the life of me find any examples of AWS Lambda functions written in Java that are triggered by Cloudwatch Scheduled events...

示例函数的奖励积分.

EDIT 1 目前还没有正确答案(虽然我不知道 AWS 已经在 SDK 中发布了一个正确的事件"对象,该对象将传递给 Lambda 函数),所以实际上可能没有我想要的答案.

EDIT 1 There is no correct answer to this yet (though I don't know that AWS has released a proper 'event' object in the SDK that would be passed to the Lambda function), so there may not actually be an answer that I was looking for.

这里也有人问过这个问题:CloudWatch Events - Schedule trigger 传递给 Lambda 函数的参数类型是什么? 有人评论说建议使用 Object 并打印类名.原来是一个LinkedHashMap.看起来和我将要得到的答案一样正确...

This question was also asked here: What is the parameter type passed to a Lambda function by a CloudWatch Events - Schedule trigger? and someone commented suggesting using Object and printing the class name. Turned out to be a LinkedHashMap. Looks to be as correct of an answer as I am going to get...

推荐答案

com.amazonaws.services.lambda.runtime.events.ScheduledEvent 是当前的答案.

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

我可以看到在 aws-lambda-java-events 库的 2.0.2 版本中这是可用的.代码是 这里 和更多关于 2.0 版本的细节是 这里

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

这篇关于AWS Lambda - CloudWatch 事件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆