Hello folks!!! In this article,we will learn how we can use EventBridge with API destination. First let us know what API destination is. With API destination features, eventbridge can integrate with services outside of aws by using rest API calls. API destinations are the third-party targets outside of aws that you can invoke with http request. Eventbridge invokes endpoints and delivers the event as a payload within the request.
Visit Webhook site:
This is a debugging site that gives us a unique URL that we can use as an endpoint to send API calls and get them echoed back. So we can see what is in the headers and in the payload.
Once we visit this site, we will copy the unique URL and save for later. We will use this URL in API destination.
Visit EventBridge and Create Connection:
1. First we will visit to our AWS management console and search for EventBridge. It will navigate us to the eventbridge page. We will click on API destination i.e. on the left menu.
2.The first thing we need to do is to create a connection. Every API destination needs one connection and this stores credentials like how to connect to that API endpoint.
3. We will click on the connection tab and then click on create connection.
4. We will create one connection named as my-connection. And in authorization type, we will select API key because there is no username and password and provide API key name and values and click on create.
5. We will see that my-connection is created successfully and its status is authorized means it is working.
Create API destination:
1.Now we have to create API destination. For this, we will click on create API destination.
2. We will create one API destination with name myAPIdestination.
3. In API destination endpoint, we will paste webhook unique URL link that we copied earlier. And in HTTP method we will use POST and set the invocation rate limit per second and we will use an existing connection and click on create.
4. Now, it’s shows that we have got an active API destination with the connection parameters that we specified.
Create event-bus in eventBridge:
1.We will create on event bus and named it as my-event-bus and click on create.
Create Rule in eventBridge:
1. Now we have to create rule that will route to the destination as a target. For this, first we will select one event bus from the drop down menu. we will select event-bus named as my-event-bus for this demo.
2. We will see that we have no rule inside our custom rule. so we will create one by clicking on create rule.
3. We will create one rule with name my-rule and choose event bus from the drop down menu and rule with an event pattern.
4. In event pattern, we will create a custom pattern.
5. We will select EventBridge API destination in target types and in destination, we will use an existing API destination and remain all as default and click on next then click on create.
6. We will see that our rule with name my-rule is successfully created.
Now when we click on my-rule, we will see our rule details.
1. Now to send a test event in the frontend, we go to event buses section and click on send events in the top right hand corner.
2. We will provide entries in event entry such as destination name as event bus, event bus as my-event-bus , and then set an event source of my event app and detail type and our payload will set this to message “hello world” and we will send this event.
3. We get confirmation that the event has been sent successfully.
4. We will see the events has now arrived in this webhook.site. It shows the raw content of the payload and all the headers that were sent as well as the API key of API value.
In this article, we have learn how we can use API destination with EventBridge.