Test that an AWS EventBridge (or CloudWatch) Event Was Fired - amazon-web-services

I'm running some integration tests on a microservice I built in AWS. One of the tests is to assert that the service triggers an AWS EventBridge event, as downstream services will need to subscribe to this event.
My question is, how do I test this in the context of my mircroservice?
I need to just assert that the event was fired in AWS. I was hoping the AWS SDK would allow some way of asserting this e.g. being able to subscribe to an event on some long polling type operation, but haven't been able to find anything.
NOTE: Not looking for test double spy answers please. The level of testing I'm doing requires confirming that an actual event has been fired in AWS EventBridge

You can create a rule for your specific event and target an SQS.
You can then read from the SQS (using long polling) and assert the event has fired.

You can check the CloudWatch metrics for your rule such as TriggeredRules, Invocations, and FailedInvocations for debugging.
Check the logging and monitoring in Amazon EventBridge here
If the rule is triggered by an event from an AWS service you can also use the TestEventPattern action to Test the event pattern of our rule with a test event to make sure the event pattern of your rule is correctly set.
For more info on how to use the TestEventPattern se TestEventPattern docs

Related

AWS EventBridge handle UpdateThingShadow event

Is it possible for AWS EventBridge to track UpdateThingShadow type of event and create a rule for those? How might an event pattern for such an update look like, and is the AWS service that we listen to AWS IOT Core, AWS CloudTrail or AWS CloudWatch?
The use case is that I do not want to expose the Device shadow directly, but have a table that reflects the state. Updating the table would trigger a custom EventBridge event that updates the table, while updating the DeviceShadow directly should trigger an AWS event that can hopefully be caught in the default AWS EventBridge. The question is what service triggers the event I might want to catch, and what EventPattern would that be.
Based on the IOT Core documentation, there is no mention of device shadow update events being triggered by the IOT Core service.
There is though, mention of monitoring UpdateThingShadow in CloudWatch. Does that mean that my EventBridge should listen to events coming in from Cloudwatch of type UpdateThingShadow?

Issue with testing an event rule that triggers a lambda

I have written an event rule that targets my lambda and is connected to the event bus. I have tested the sample event against my event pattern with test-event-pattern in the aws cli and in the rules section in the aws console and the event pattern matches.
However, while raising an event to the eventbridge my rule is not being triggered, but the event is successfully put in the event bus.
A strange thing I've also noticed is that the rule isn't showing up in cloudwatch metrics.
I can confirm that the rule is enabled and has the correct connections and permissions and I would like help figuring out why it still isn't being matched with my sample events
Is the rule created against the correct event bus? Are you adding the event to one, and creating the rule on another.

AWS EventBridge Rule Event Pattern

this is the architecture that I have now.
Lambda (Put events to event bus) -> Event Bridge -> Event bus in another AWS account
Right now, lambda is putting events using putEvents API to Event Bridge. Now I want to send these events to another Event bus but in a different AWS account. I'm wondering what kind of event pattern should I need to create for the rule?
The event pattern does not change. But the target changes. In your case, to forward events to different account you have to choose special target for that:

How to extract event relayed from AWS EventBridge to ECS Fargate

I articulate the question as follows:
Is the EventBridge event relayed to the ECS Task? (I can't see how much useful it could be if the event is not relayed).
If the event is relayed, then how to able to extract it from within say a Node app running as Task.
Some Context is Due: It is possible to set an EventBridge rule to trigger ECS Fargate Tasks as the result of events sourced from, say, CodeCommit. Mind you, the issue here is the sink/target, not the source. I was able to trigger a Fargate Task as I updated my repo. I could have used other events. My challenge resides in extracting the event relayed (in this case, repository name, commitId, etc from Fargate.)
The EventBridge documentation is clear on how to set the rules to trigger events but is mum on how events can be extracted - which makes sense as the sink/target documentation would have the necessary reference. But ECS documentation is not clear on how to extract relayed events.
I was able to inspect the metadata and process.env. I could not find the event in either of the stores.
I have added a CloudWatch Log Group as a target for the same rule and was able to extract the event. So it certainly relayed to some of the targets, but not sure if events are relayed to ECS Task.
Therefore, the questions arise: is the event relayed to the ECS Task? If so, how would you access it?

AWS CodeCommit: Repository Notifications vs Repository Triggers

Notifications: https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-repository-email.html
Triggers: https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-notify.html
The official document states that for CodeCommit repository 'events which follow CloudWatch Event Rules' (like pull requests), we use Repository Notifications.
Whereas for CodeCommit repository events which are just 'operational events' (like creating branches, pushing code to a branch), we use Repository Triggers.
I don't understand the difference between 'events which follow CloudWatch Event Rules' and 'operational events'. For me, both pull requests and pushing code to branch seem similar events.
Thus, confused between why we need both Repository Notifications and Repository Triggers.
I have asked the same question today and I found this on docs:
Repository notifications are different from repository triggers. Although you can configure a trigger to use Amazon SNS to send emails about some repository events, those events are limited to operational events, such as creating branches and pushing code to a branch. Triggers do not use CloudWatch Events rules to evaluate repository events. They are more limited in scope. For more information about using triggers, see Manage Triggers for a Repository.
IMO, AWS documentation has not clearly stated the difference between notification and triggers and cloudwatch events. Here is my understanding :
Notifications should be used for literal notification and not for taking action based on them.
Triggers are supposed to initiate action. So, if I need to invoke some service based on this event on which trigger is based, I would do that and hence the option to integrate Lambda service. In a way to add automation after codecommit events.
However, Cloudwatch Events provide a wide variety of integration option for codecommit events which are not available with trigger.