Use EventBridge to handle API requests

03 Jan, 2023
Xebia Background Header Wave

At AWS re:Invent I attended SVS312 Building Serverlesspresso. This talk was about how you can create event-driven architectures. I am a fan of event-driven architectures. So I wanted to highlight a interesting technique using EventBridge shown in this talk.

In the past I used a similar technique that I talked about in an AWS Meetup. Here I used an API Gateway to post the request to a SQS Queue. This is very useful for fire and forget patterns. Because you do not need to invoke a Lambda function to handle the request. The response to the user is faster and you do not need to pay for the Lambda invocation.

But James Beswick showed a iteration on that pattern. Instead of posting your payload to a SQS Queue you can also create an event within EventBridge. The initial request can still be a fire and forget call, but James did something interesting here.

Because the API request itself became an event, you are able to process the API request as an event.

A closer look

All examples are coming from the actual serverless-coffee repository from AWS

When you order a coffee a POST call is executed. The API Gateway uses the x-amazon-apigateway-integration extension. This enables you to pass the body of the request as the details of an EventBridge event.

From here you can do all sorts of actions. For example, the serverless-coffee project used IOT Core. With IOT Core you can notify the end-user with status updates. And notify the barista that what kind of coffee needs to be created.

The advantage of this is that these two actions are completely decoupled from each other. In fact the initial request is decoupled from these two actions. This makes this pattern very extendable! You do not need to take into account what other services are there.


Using EventBridge to handle your API requests can be very powerful. But it does need you to poll for updates or use streamed updates using IOT Core.

When you see what kind of flexibility you get extendability it is worth it!

Photo by Josh Sorenson

Joris Conijn
Joris has been working with the AWS cloud since 2009 and focussing on building event driven architectures. While working with the cloud from (almost) the start he has seen most of the services being launched. Joris strongly believes in automation and infrastructure as code and is open to learn new things and experiment with them, because that is the way to learn and grow. In his spare time he enjoys running and runs a small micro brewery from his home.

Get in touch with us to learn more about the subject and related solutions

Explore related posts