0

Following up on a question I asked previously: Mocking an AWS ScheduledEvent class using C# .NET

I have setup an EventBridge (EB) rule that runs every 5 minutes and targets a Lambda that ingests JSON data from the EB rule. The JSON is very simple:

{
  "BatchSize": 10,
  "BatchRetries": 3
}

My target Lambda is in C# 6 .NET and has a class for deserializing the data:

public class EventBridgeDetailDto : Detail
{
    public int BatchSize { get; set; }
    public int BatchRetries { get; set; }
}

My Lambda's handler looks like so:

public async Task FunctionHandler(ScheduledEvent scheduledEvent, ILambdaContext context){
}

My understanding is that the JSON from the EB event would be in scheduledEvent.Detail but that property is always null. What am I getting wrong?

TortillaCurtain
  • 501
  • 4
  • 18

1 Answers1

0

If you configure the lambda to be triggered by the EventBridge scheduler every 5 minutes, using a custom payload, then the lambda function will only receive the custom payload object. Note that, the lambda function will receive CloudWatchEvent<T> events only when those events are published via the EventBus.

In your scenario, you directly consume the payload from the scheduler, not from the EventBus. So you have to use your EventBridgeDetailDto class directly to consume the payload.

public async Task FunctionHandler(EventBridgeDetailDto payload, ILambdaContext context){
}

Also, there is no need to inherit your EventBridgeDetailDto class from the Detail data type, as it is not applicable to your use case.

public class EventBridgeDetailDto
{
    public int BatchSize { get; set; }
    public int BatchRetries { get; set; }
}
codeninja.sj
  • 3,452
  • 1
  • 20
  • 37