How to Orchestrate AWS Lambda using Camunda Cloud: Powerful Serverless Function Orchestration using BPMN and Cloud-Native Workflow Technology

By
Zeebe clusters
  • Blog
  • >
  • How to Orchestrate AWS Lambda using Camunda Cloud: Powerful Serverless Function Orchestration using BPMN and Cloud-Native Workflow Technology
TOPICS

30 Day Free Trial

Bring together legacy systems, RPA bots, microservices and more with Camunda

Sign Up for Camunda Content

Get the latest on Camunda features, events, top trends, and more.

TRENDING CONTENT

I recently spoke at the AWS Community Summit and wanted to share how BPMN and cloud-native workflow technology are a straightforward and highly visual way of orchestrating multiple AWS Lambdas to achieve a bigger goal.

The example I used in my talk was a trip booking, composed of a hotel booking, a rental car booking and a flight booking:

Book a trip

This example raises a lot of questions about how the functions are coordinated to achieve this goal.

In this post I will describe why orchestration is a good choice — and how you can use BPMN and Camunda Cloud to orchestrate these three AWS Lambdas and provide an additional trip booking Lambda. I will also tackle why you might want to prefer BPMN over AWS Step Functions. All sources and a step-by-step tutorial are available on GitHub: https://github.com/berndruecker/trip-booking-saga-serverless/tree/master/zeebe/aws.

Why Orchestration?

In the talk I discuss alternative approaches, for example to chain the lambdas by using events in between. This would be a so-called choreography which tends to become hard to understand and change. I illustrated this in my slides.

So ideally you want to express the orchestration logic somewhere. But these orchestrations are seldom simple. For example, you have to deal with flight bookings that don’t go through. In this case you cannot simply rollback the transaction of the hotel or rental car booking. Instead, you have to cancel or undo these bookings in your business logic. This is known as the Saga Pattern and can be expressed in BPMN relatively easy:

Saga pattern

Orchestrating Lambdas With BPMN

In BPMN you can have service tasks where you can execute logic. This is a great place to invokes Lambdas. I will use Camunda Cloud as managed workflow engine (based on Zeebe) that can execute such BPMN models. Workflow engine clusters can be created in self-service (register for a free trial):

Zeebe clusters

In order to connect Zeebe to AWS Lambdas you can use the Zeebe Lambda Worker, which is available as community extension (early stage at the time or writing). This allows you to wire your Lambda invocations directly within your BPMN:

Lambda

You can use workflow variables to store data related to your workflow instance, for example the result of the hotel booking. These variables can be used at other places, e.g. to make decisions:

Decisions

The Zeebe Lambda worker itself can be operated as Docker image. It subscribes to Zeebe and invokes Lambdas. It can run within your AWS account, so you don’t need to expose your Lambdas to the outside world. You could simply operate the worker e.g. via AWS Fargate. Refer to the docs for details.

EventBridge

We currently spike AWS EventBridge support as an alternative to this worker, which could even ease the integration further.

Lambdas can also talk to the Zeebe workflow engine via existing client libraries, e.g. to trigger new workflows from within the trip booking function:

const ZB = require('zeebe-node')
module.exports.handler = (input, context, callback) => {
  const variables = JSON.parse(input.body);
  const zbc = new ZB.ZBClient({
    camundaCloud: {
      clientId: process.env.ZEEBE_CLIENT_ID,
      clientSecret: process.env.ZEEBE_CLIENT_SECRET,
      clusterId: process.env.ZEEBE_CLUSTER_ID  
    }
  })
  zbc.createWorkflowInstance('trip-booking', variables); 
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Trip booking started'
    }),
  };
  callback(null, response);
};

How to run?

Follow the read-me of https://github.com/berndruecker/trip-booking-saga-serverless/tree/master/zeebe/aws. It will walk you through the steps:

  1. Deploy the functions to book or cancel a hotel, car and flight. The example leverages the Serverless Framework for this but you could also deploy in your favorite way.
  2. Sign up for a Camunda Cloud account and create a Zeebe cluster.
  3. Deploy the workflow model
  4. Run the Zeebe Lambda Worker
  5. Deploy the function to book a trip
  6. Start using your function, e.g. via CURL, and inspect what is going on in Operate.

A complete walk-through recording is available here: https://youtu.be/RqOSwinvl-U

Orchestrate AWS Lambda using Camunda Cloud

Why BPMN for Lambda Orchestration?

You might wonder why you should use BPMN instead of simply going for AWS Step Functions, which is available directly within the AWS universe? Good question!
I would name three main reasons:

  • BPMN is a mature and feature-rich language that is well-known and adopted in the industry. It is also an ISO standard.
  • The visualization matters. Graphical models that can be understood by different stakeholders are super important.
  • Lambda orchestration is often only one piece of a broader orchestration story we see at customers.

Let’s elaborate.

The BPMN language

I can simply repeat what I wrote recently on the Camunda Forum:

BPMN is much more powerful. You are missing a lot of concepts in the AWS State Language, like timers (Step Functions is reduced for waiting with timeout), compensation or scoping (subprocesses). Of course Step Functions can eventually implement these concepts, but keep in mind that this also means: reinventing them. What I personally like about BPMN is that it is an ISO standard, so a lot of important players in the industry agreed on it and it is well discussed — so you can be sure important concepts are tackled and got right. I know that standards overall don’t have the best reputation at the moment, but I am convinced that they are very useful given a wide adoption like BPMN. A lot of people know it, so it is basically about proprietary vs. standard flow languages.

Visualization

With Camunda you get BPMN models, which are well-known around the globe by various stakeholders. You can model your flows graphically, but you are not forced to do it by the way. You can also define your flow in Java DSL. In this case, you still have a BPMN visualization (auto-layout). BPMN models enable a BizDevOps mindset as these models can be read by business people as well as developers as well as in operations. This is not the case with Step Function visualizations.

Talking about operations: Have a look at Camunda Cockpit and compare this to the AWS tooling, which I think speaks for itself.

Some comparison can also be found in BPMN and Microservices Orchestration, Part 2 of 2: Graphical Models, Simplified Sagas, and Cross-functional Collaboration:

BPMN-AWS

I wrote about that in length in BizDevOps — the true value proposition of workflow engines.

Orchestrate Anything

Customers typically not only orchestrate Lambdas, but they have an entire zoo of things they need to orchestrate, e.g. Legacy Systems (often on-prem), their monolith, microservices, RPA Bots, Functions, External Services, Business Rules probably expressed in DMN and much more.

Step Functions can’t deliver this, as they are cloud only and, in fact, AWS only. While they integrate into the AWS universe natively, they are a stranger in the outside world or on-prem.
Camunda, on the other hand, is super flexible in this regard. We have customers running it on-prem, in their own cloud environments or in the public cloud of different vendors. You can easily orchestrate Azure Functions, even within the same workflow. The publish/subscribe concept of the workflow engines makes it super easy, to run on-prem workers in combination with a managed workflow engine.

Conclusion

This post quickly walked you through Lambda orchestration with BPMN and Camunda Cloud. This should give you some starting point for your own endeavors. While Step Functions might be the tool of choice for easy orchestrations, you might soon want to switch to a standardized, mature and widespread workflow language (BPMN), where the visualization can be understood by anyone. It will allow you to orchestrate anything, anywhere.

If you want to see some real-world examples of AWS Lambda orchestration with BPMN – check out this blog post from MINEKO, who use Camunda Cloud and the Zeebe workflow engine.

Camunda Developer Community

Join Camunda’s global community of developers sharing code, advice, and meaningful experiences

Try All Features of Camunda

Related Content

Process blueprints can now be found on Camunda marketplace! Read on to learn how they can help you and how you can contribute.
Achieve operational superiority with the intelligent backbone of service orchestration. Learn how and why you should orchestrate your services.
Learn about how AI automation can help you and your business thrive. Get insights into how you can lower costs, scale faster, improve service and more with AI.