Search code examples
c#.netaws-event-bridgeaws-sdk-net

How to troubleshoot why event doesn't reach the target setup in the event bridge


I have two different aws accounts with similar environment AFAICT. I setup an event-bridge/rule/target in each environment. I used same event pattern in rule in both environments. I then setup separate admin user in each environments with same permissions. Following code works fine in one environment (meaning the event reaches the target) but doesn't work in the other environment. However, for the environment where it doesn't work, the code still returns a result.HttpStatusCode of OK.

string awsAccessKey = "whateveraccesskey"; 
string awsSecretKey = "whateversecretkey"; 
string awsEventBusName = "myEventBus"; 
string awsEventSourceName = "mySource"; 
Amazon.RegionEndpoint regionEndpoint = Amazon.RegionEndpoint.USEast1;  

AmazonEventBridgeClient ebClient = new AmazonEventBridgeClient(awsAccessKey, awsSecretKey, regionEndpoint);  
var eventRequestEntry = new PutEventsRequestEntry() 
{     
    DetailType = "Test Detail Type",     
    EventBusName = awsEventBusName,     
    Source = awsEventSourceName,     
    Detail = "Test Details",     
    Time = DateTime.Now 
};   

PutEventsResponse result = await ebClient.PutEventsAsync(new PutEventsRequest() 
{     
    Entries = new List<PutEventsRequestEntry>() { eventRequestEntry } 
}).ConfigureAwait(false);  
if (result != null) 
{     
    Console.WriteLine($"StatusCode {result.HttpStatusCode}"); 
} 
else 
{     
    Console.WriteLine("null result"); 
} 

I am just not sure how to troubleshoot the code or that aws environment to determine why this event doesn't reach the target. Any hints or ideas will be highly appreciated.


Solution

  • Can you see in the rule metrics that it matches/invokes the target? Is the event bus name/arn correct (you'll not get an error for publishing to a non-existent event bus)? You can also set up a dead-letter queue per target (https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_Target.html#eventbridge-Type-Target-DeadLetterConfig) to capture any error (I recommend to set retries=0 so it will immediately DLQ events).