没有在预定的事件中得到输入

Not getting input in scheduled event

我有一个由 lambda cloudwatch 规则触发的 lambda。这是通过 cloudformation

创建的 cloudwatch 规则
Resources:
  CloudWatchRule:
    Type: AWS::Events::Rule
    Properties:
      Name: !Sub CloudWatchRule-${Stage}
      Description: "Scheduled event to fetch keys for score generation every hour"
      ScheduleExpression: "rate(2 minutes)"
      Targets:
        - Arn:
            Fn::GetAtt: [FetcherLambda, Arn]
          Id: "CloudWatchEvent"
          Input: '{"hours": 3}'

  CloudWatchRulePermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName:
        Ref: FetcherLambda
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn:
        Fn::GetAtt: [CloudWatchRule, Arn]

我可以在控制台中看到输入在 Constant(Json) 字段中。

但是在处理程序中,当我记录时,我得到的是空事件,

public Void handleRequest(final ScheduledEvent scheduledEvent, final Context context) {
        log.info("Received event: {}", scheduledEvent);
        return null;
    }

我收到的日志为 Received event: {}

我是不是遗漏了什么,或者是否还需要其他任何东西才能在此处获取输入

我认为问题在于您使用 ScheduledEvent class 作为输入。当您指定来自规则的输入时,您不会获得任何其余的计划数据(来自 AWS::Events::Rule Target - Input):

If you use this property, nothing from the event text itself is passed to the target.

为了获得您期望的数据,您需要 class 是可以从您指定的输入序列化的东西。