AWS - Can't see Event Bridge Rule on Custom Bus - amazon-web-services

I'm trying to target a Lambda function with an EventBridge Rule. When I go to set the Lambda trigger, the only rules I've ever been able to see were ones attached to the default bus. Why can't my Lambda Trigger UI see rules when they are on my custom bus?
Any help or explanation would be greatly appreciatd.

This is UI limitation. You have to setup up the connection between your EB custom bus and your lambda function using EventBridge UI.

Related

List & Remove an EventBridge Lambda trigger using the CLI

I need to fetch information from a lambda function and remove an existing trigger (EventBridge) from this lambda using CLI (script needs to do that).
Tried to use list-event-source-mappings or delete-event-source-mappings but without success.
Seems like EventBridge isn't supported yet (showing me only SQS,Kinesis,DynamoDB,MQ,MSK) but maybe I am wrong and there is a solution?
Edit:
I have a working lambda function that has associated trigger with an Eventbridge rule which was already deleted in the past. It no longer exists in my account, but, I still see it under my Lambda trigger (it also says that this rule cannot be found any more because it is deleted - again, it still appears in my Lambda trigger and I want to CLEAN it using CLI.) I wish to DELETE the association (trigger) from my Lambda, not to delete the EventBridge TARGET which is the Lambda.
The APIs you are looking for are in the EventBridge events client:
aws events list-rule-names-by-target --target-arn <lambda-arn>
aws events list-targets-by-rule --rule <rule-name-from-previous>
aws events remove-targets --rule <rule-name-from-previous> --ids <target-id-from-previous>
Note: The terminology is a bit confusing. An Event Source Mapping is the technical term for the particular polling-type Lambda integration pattern that handles the sources you mention. It is not related to EventBridge events.
You should be able to use events command:
aws events list-rule-names-by-target --target-arn <target_arn>
This will list the names of the rules that are associated with the specified target_arn. You can then use the aws events describe-rule command to get more information about each rule, including the rule id, schedule and pattern.
aws events describe-rule --name <rule_name>
Now to remove a trigger for a Lambda function in EventBridge:
aws events remove-targets --rule <rule_name> --ids <target_id>
The target_id is the unique identifier for the trigger that you want to remove, and the rule_name is the name of the rule that the trigger is associated with.

Scheduled EventBridge rule targeting API Destination

Is it possible to create an EventBrisge rule which can be scheduled to run at a certain time of day and call an API as a custom target?
It seems as though a schedule can be setup for targets if they are AWS or Partner services, but not if they are custom configured endpoints.
All I want to do is setup a daily routine to call an endpoint so it can perform a daily cleanup task. If there is a better way, can someone suggest it, please?
EDIT
Under EventBridge I have created a Connection which points at the OAuth endpoint and then an API Destination which points at the API endpoint I want to invoke on a daily basis.
I have then created an event bus and a rule but when I try to set the Schedule option on the rule it shows a warning which states:
Schedule rule is not supported when custom or partner event bus is
selected
I believe this means that I cannot invoke my own API endpoint with EventBridge without going through a Lambda. Am I wrong?
Create your scheduled rule on the *default bus* using the Create Rule interface. It appears you are right that the brand-new EventBridge Scheduler console interface does not yet (?) support API Destinations.
The "create rule" scheduling supports cron-type use cases like yours. EventBridge Scheduler adds new functionality like ad-hoc scheduling of one-off events, flexible time windows, and TZ-aware scheduling.

Can I send events to EventBridge via Lambda?

I want to simply send an event from a lambda function TO an event bridge. Every thing that I search online is the other way around. And If I go to the AWS console and try to find lambda as an event source, nothing comes up.
Can I send a custom event to an event bridge from Lambda?
Yes you can, but only to a custom EB bus and using AWS SDK's put_events. In other words, you have to do it programmatically. There is no automatic integration between lambda and custom EB bus.

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 SQS trigger Step Functions

Quick question: Is it possible to trigger the execution of a Step Function after an SQS message was sent?, if so, how would you specify it into the cloudformation yaml file?
Thanks in advance.
The first think to consider is this: do you really need to use SQS to start a Step Functions state machine? Can you use API gateway instead? Or could you write your messages to a S3 bucket and use the CloudWatch events to start a state machine?
If you must use SQS, then you will need to have a lambda function to act as a proxy. You will need to set up the queue as a lambda trigger, and you will need to write a lambda that can parse the SQS message and make the appropriate call to the Step Functions StartExecution API.
I’m on mobile, so I can’t type up the yaml right now, but if you need it, I can try to update with it later. For now, here is detailed walkthrough of how to invoke a Step Functions state machine from Lambda (including example yaml), and here is walkthrough of how to use CloudFormation to set up SQS to trigger a Lambda.
EventBridge Pipes (launched at re:Invent 2022) allows you to trigger Step Functions State Machines without need for a Lambda function.
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes.html
You can find an example here:
https://github.com/aws-samples/aws-stepfunctions-examples/blob/main/sam/demo-trigger-stepfunctions-from-sqs/template.yaml