Serverlesspresso - AWS Workshop Hands-On

16.08.2023Jacek Blazynski
Cloud Serverless workshop Amazon Web Services workflow

Welcome to my first tech-up with b-nova, where I’ll introduce you to a tasty serverless use case based on AWS technologies, while following the AWS Serverlesspresso Hands-On Workshop.

The AWS console provides a relatively easy setup with preconfigured backbone infrastructure, which gave a positive outlook for what was to come. As I followed the guide, the magic began to unfold. But first, let’s clarify what Serverless means.

A brief introduction to Serverless

Serverless computing has evolved significantly since its inception in the early 2010s. Companies like AWS, Google, and Microsoft have pioneered serverless technologies, revolutionizing how we build and deploy applications. The core principle behind Serverless is to abstract the infrastructure layer, enabling developers to focus solely on their code without worrying about server management or scaling. Today, serverless on AWS encompasses over 200 fully-featured services catering to a wide range of technologies, industries, and use cases, but it all started with AWS Lambda. Read more about Serverless in our dedicated Serverless TechUp.

In 2014, AWS Lambda was introduced as one of the first serverless compute services, paving the way for a new era in cloud computing. Google followed suit with Google Cloud Functions in 2016, and Microsoft launched Azure Functions the same year. To delve further into Serverless insights, you can read Raffi’s Serverless Patterns TechUp to learn more about Serverless Patterns.

What’s behind the Serverlesspresso Workshop

The AWS Serverlesspresso Workshop was first showcased at the 2021 AWS re:Invent conference. It featured a fun and interactive coffee ordering system, providing participants with an opportunity to explore key AWS serverless services and witness the evolution of this groundbreaking technology firsthand. Users could simply scan a QR code at the counter to order their favorite dark think juice!

By going through the Serverlesspresso workshop, you’ll gain a better understanding of the AWS serverless stack. This hands-on learning experience is designed as an entry-level showcase of the power and simplicity of serverless technologies. While it won’t dive deep into the technical details, it’s enough to get your hands dirty.

The workshop highlights key AWS services that allow you to build scalable and cost-efficient PAYG (Pay-As-You-Go) applications without the burden of managing servers. Throughout the workshop, we’ll be working with the following key services.

AWS Services used during the Workshop

Amazon API Gateway

Amazon API Gateway

Figure: Source: AWS

The journey begins with Amazon API Gateway, a fully managed service for creating, publishing, and maintaining APIs. It acts as the bridge between the frontend application and backend services like AWS Lambda, forming the backbone of the Serverlesspresso system. You’ll find helpful diagrams in the overview section of the tutorial to get a better picture of how the underlying platform is built for the entire service to run.

AWS Lambda

AWS Lambda

Figure: Source: AWS

Next up is AWS Lambda, a compute service that executes code in response to triggers. With Lambda, you can implement serverless functions for processing customer orders, updating the database, and sending notifications without the need to provision or manage servers. Lambda functions play a central role in the Serverlesspresso system, handling the logic behind each step of the order process.

DynamoDB

DynamoDB

Figure: Source: AWS

As you progress through the workshop, you’ll interact with Amazon DynamoDB, a NoSQL database service for high-performance and consistent data storage. Within the context of Serverlesspresso, DynamoDB stores order details, customer information, and barista updates, ensuring that data remains available and accessible throughout the ordering process.

AWS Step Functions

AWS Step Functions

Figure: Source: AWS

Now, let’s focus on the main point of interest – AWS Step Functions! It’s a serverless workflow service for coordinating distributed applications. Step Functions make it easy to orchestrate the flow of information among the various AWS services involved in Serverlesspresso. With the Workflow Studio visual interface, we will create a state machine to manage the order processing steps, such as receiving an order, preparing the coffee, and sending a completion notification to the customer.

Amazon EventBridge

Amazon EventBridge

Figure: Source: AWS

Last but not least, the workshop introduces Amazon EventBridge, a serverless event bus crucial for connecting applications with data streams. EventBridge allows you to decouple the different components of the Serverlesspresso system, making it more modular and easier to maintain. We’ll configure it to listen for specific events, such as “order placed” or “order completed”. EventBridge enables seamless communication between Lambda functions, Step Functions, and DynamoDB, ensuring that data flows smoothly throughout the entire process.

What’s cooking during the Serverlesspresso Workshop?

When a user scans the QR code to order a coffee, the AWS Serverlesspresso workflow is initiated. The AWS Step Functions and Amazon EventBridge services work in tandem to orchestrate the flow of information from user interfaces to the database and back. To picture the process that occurs see the simplified graph with three visual interfaces (ordering mobile app, baristas terminal, and info display).

Figure: Source: AWS

Let’s look at the individual steps involved in ordering a serverlesspresso coffee:

  • User scans the QR code
  • API Gateway receives the request
  • API Gateway triggers a Lambda function
  • Lambda function creates a new order in DynamoDB
  • Lambda function initiates a Step Functions workflow
  • Workflow manages the order processing steps
  • Order received
  • Coffee preparation
  • Order completion notification
  • EventBridge listens for specific events
  • Event: Order placed
  • Lambda function processes the order
  • Event: Coffee prepared
  • Lambda function updates the order status in DynamoDB
  • Event: Order completed
  • Lambda function sends a notification to the user

There’s quite a lot going on over here, so to make sure all is working in the right order it would be great to have some kind of a diagram or a flowchart, right? This is where Step Functions come into play!

Creating a Workflow with AWS Step Functions Workflow Studio

The Workflow Studio is a visual interface in the AWS Step Functions console that simplifies the process of designing and creating workflows. It allows you to visually design state machines using drag-and-drop actions, helping you define and prototype your workflows more quickly.

What is a State Machine you ask?

Lets imagine the process of making coffee. We need our beans, water and clean cup. What’s the state of the beans, do we need to grind them before we brew the coffee? Water, is it hot or cold? Do we still need to wash our favourite cup? State machine will take care of the process of making a coffee taking all the states into consideration. Given the conditions we set up are correct, we can trust that the state machine will serve us with a nice hot cup of our favourite brew.

…now back to the nitty gritty:

In Serverlesspresso we are dealing with two state machines, one the “OrderProcessorWorkflow” that we have to build, and “OrderManagerWorkflow” that’s already set up. Both of which orchestrate respective states of the ordering process. Our main task in this workshop is to complete the build with “OrderProcessorWorkflow” that will be taking care of the following:

  • Checking shop’s status and capacity
  • Managing order lifecycle events
  • Handling customer and barista timeouts
  • Generating order numbers
  • Emitting events for system coordination

After getting used to the clunky AWS console, it took me good few hours to complete our state machine. There are many checkpoints on the way to make sure that you’re on the right track after jumping from one module to another. In the end our workflow should look more or less like this:

Figure: Source: AWS

The whole workflow is defined in ASL (Amazon States Language) and can be exported to json or yaml file.

Figure: Screenshot of AWS Console

Having our state machine ready is great, now to make sure it does what it’s supposed to do at the right time, we will add some events and event listeners, so that our services can talk to each other in the right manner.

EventBridge Choreography

The two state machines provided make great use of AWS EventBridge as an integral part of an event-driven architecture. It helps to route, filter, and transform events while reducing the need for traditional polling and request-response mechanisms. In both state machines, EventBridge is used to emit events at various stages of the workflow. The events contain relevant data such as task tokens, user IDs, order IDs, and order numbers. This information is crucial to keep track of the progress and status of different orders, ensuring that each step is executed as expected.

Troubleshooting with Step Functions

It wouldn’t have been a successful workshop if everything worked right off the bat. At one point, I encountered a workflow error caused by a misconfigured event emitter. Initially, it was not clear what the problem was, as I thought I had followed all the steps from the tutorial. Step Functions helped me troubleshoot and identify the issue. By checking the visual workflow representation, I could pinpoint the exact step where the process was stalling. I realized that the missing TaskToken message was caused by the event emitter not waiting for another process to finish. This allowed me to rectify the event emitter’s setup to properly “wait for the callback,” resulting in a seamless workflow execution. Ta-da!

Conclusion

Completing the AWS Serverless Espresso Workshop has been a generally positive and satisfying experience, despite the sometimes clunky and messy console UX. I’ve built dynamic, intricate workflows with Step Functions, removing the need for custom code by integrating directly with DynamoDB and EventBridge. It was fulfilling to see the order process unfold from the initial CLI command to the final stages, with wait states mirroring real-life human interactions.

Given that the serverless topic is getting hot again, and not necessarily because of its obvious benefits, I personally believe that this particular use case shows the power and flexibility of the AWS serverless stack. By coordinating multiple tasks and interacting with other AWS services, Step Functions enable us to build scalable, fault-tolerant, maintainable applications, and most importantly, helps us enjoy our coffee!

Serverlesspresso Workshop Serverlesspresso GitHub

Jacek Blazynski

From software development to bike mechanics, I've navigated the IT galaxy like a true space explorer. Now thriving as a Padawan Developer, I'm on a constant quest for innovation, collaboration, and the next big cosmic challenge in the tech universe.