Coder Social home page Coder Social logo

maxsu / statefun-aws-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tzulitai/statefun-aws-demo

1.0 2.0 0.0 635 KB

A stateful serverless demo app running on AWS Lambda, using Apache Flink Stateful Functions

License: Apache License 2.0

Dockerfile 6.47% Python 70.67% Shell 22.86%

statefun-aws-demo's Introduction

Stateful Serverless App with Stateful Functions and AWS

This is a complementary demo application to go with the Apache Flink community blog post, Stateful Functions Internals: Behind the scenes of Stateful Serverless, which walks you through the details of Stateful Functions' runtime.

The demo is a simple shopping cart application, whose architecture consists of the following parts:

  • Functions written using Stateful Functions' Python SDK, serviced via AWS Lambda and AWS API Gateway as a serverless deployment.
  • A StateFun cluster running on Kubernetes (AWS EKS), playing the role of an event-driven database that manages state and message routing for the serverless functions.
  • AWS Kinesis streams serving as the ingress and egress of application events.
  • An AWS S3 bucket to persist periodic checkpoints of the function states for durability and fault-tolerance.

Stateful Functions

Please refer to the blog post for further details.

Project structure

  • app/: Contains the function code that defines the business logic, written as AWS Lambda functions.
  • protobuf/: Contains Protobuf definitions of the message and state types that the functions use.
  • Dockerfile: Dockerfile for building the image that will be used to deploy the StateFun cluster.
  • k8s/: Contains Helm templates to deploy the StateFun cluster on Kubernetes.
  • build-*.sh: Tool scripts for preparing deployment resources, such as AWS Lambda packages and Kubernetes deployment templates.

Running the demo

Prerequisities

  • Have Helm, Docker, and kubectl installed.
  • A running Kubernetes cluster with access to AWS Kinesis and AWS S3. This demo assumes that you are using AWS EKS, which would contain the necessary credentials in the cluster node environments.
  • Created AWS Kinesis streams cart_events and cart_results.
  • A S3 bucket for persisting periodic checkpoints. The tutorial below assumes you've created the bucket at s3:///checkpoints/.

Procedures

Step 1: Package and upload the AWS Lambda functions

$ ./build_lambda_packages.sh

This creates a package at aws_lambda_package/shopping_cart_lambda_function.zip.

Once done, you need to:

After completing this step, you should now have an API endpoint URL (e.g. https://abcdxyz.execute-api.us-west-1.amazonaws.com/default/shopping-cart) for invoking the functions.

Step 2: Deploy the StateFun cluster on Kubernetes

$ ./build_k8s_resources.sh -t <image-tag> -e <lambda-endpoint-url> -c <s3-checkpoint-dir>

For example, assuming the resources we've prepared so far:

$ ./build_k8s_resources.sh \
    -t tzulitai/statefun-aws-demo \
    -e https://abcdxyz.execute-api.us-west-1.amazonaws.com/default/shopping-cart \
    -s s3:///checkpoints/

This builds the Docker image for the StateFun cluster, as well as a statefun-k8s.yaml for deploying the cluster.

Once done, you need to:

  • Upload the Docker image to the Dockerhub public registry.
  • kubectl create -f statefun-k8s.yaml to deploy the cluster.

statefun-aws-demo's People

Contributors

tzulitai avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.