REST API with Step Function Integration

Understand the integration of step functions with API Gateway.

Step functions

Workflow orchestration is an important component of large-scale applications. It’s true that we can implement complex systems fully in code. However, it makes sense to split the code into independent pieces that are connected together by a framework. Consider, for example, an e-commerce application. Whenever a user places a new order, it triggers several processes. On a high level, the payment confirmation is followed by procurement and then dispatch management.

It's possible to do all these in a sequential code flow, where one master code block invokes the individual methods, one after the other. However, such an implementation isn’t modular and is difficult to maintain and enhance. Instead, we can create individual services that are orchestrated in a workflow. Step functions help us with such orchestration.

Thus, a new order can trigger a step function, which invokes individual services. The step functions provide versatile features. It can invoke services and wait for confirmations. It can make decisions based on such responses. It can do this in sequences and loops. Step functions can create workflows that last up to a year long. That can include human interaction as well as other external dependencies.

The workflows are often not that complex. For simpler cases, we have express workflows that can live up to five minutes. Naturally, they cost less than the standard workflows. Let’s check out a simple example of express workflows and how they can work with API Gateway.

Hosting public API

Consider a public API server (like RapidAPI) that sells APIs. We need a lot of analytics around each API hosted on the platform. We should track each API invocation for billing and performance analysis. We need a consistent framework to track the number of requests, errors, latency, and other metrics for each invocation of each API.

Step functions provide a perfect pattern for solving this problem. We can integrate all the APIs in the platform using step functions (express flow). One defined step in the express flow can be dedicated to the business logic, while the others can meter and audit theAPIs. That makes a consistent framework for all the APIs.

Get hands-on with 1200+ tech skills courses.