DEV Community

Cover image for Use EventBridge to handle API requests
Joris Conijn for AWS Community Builders

Posted on • Originally published at xebia.com

3

Use EventBridge to handle API requests

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.

Conclusion

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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post