Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting input in scheduled event

I have a lambda which gets triggered by lambda cloudwatch rule. This is the cloudwatch rule created via cloudformation

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]

I can see in the console that the input is there in Constant(Json) field.

But in the handler, when I am logging I am getting empty event,

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

I am getting a log as Received event: {}

Am I missing something or is there anything else needed to get the input here

like image 731
Nitika Avatar asked Jan 23 '26 19:01

Nitika


1 Answers

I believe the issue is that you are using the ScheduledEvent class as your input. When you specify the input from a rule you do not get any of the rest of the schedule data (from AWS::Events::Rule Target - Input):

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

In order to get the data you are expecting you need the class to be something that will be serializable from the input you specify.

like image 77
Jason Wadsworth Avatar answered Jan 25 '26 10:01

Jason Wadsworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!