Example Full-stack Serverless project using ReactJS, Momento Topics, Step Functions, API Gateway, ECS, Lambda, DynamoDB with streams, and more to build an online pizza shop where the progress of orders is updated automatically in the UI.
Containers running in ECS fargate which make and deliver the Pizza orders are coded in Rust. Lambda functions to handle orders and their progression are coded in Python Front End is coded using ReactJS.
Backend is deployed using Terraform.
ordering-backend/terraform
- Contains all the files in the Terraform stack to deploy everything in the backend including Step Functions, DynamoDB table, VPC, ECS Cluster, ECS Tasks, Lambda functions, and more.ordering-backend/apis
- Open API spec files for the ordering API Gatewayordering-backend/containers
- scripts and source for the containers that make the pizza and deliver it. Need to run the install script to create ECR repos for the containers and build/push themordering-backend/ecs-tasks
- ECS Task deifinitions for the Rust ECS workersordering-backend/functions
- Source code for the Python functions used by the ordering API and DynamoDB Streams handlerordering-backend/state-machines
- Template file for the Step Functionordering-frontend
- The ReactJS front end for the serverless pizza shop
- Terraform CLI (https://developer.hashicorp.com/terraform/install)
- Rust and Cargo tools (https://www.cargo-lambda.info/guide/getting-started.html)
- Need to setup a Momento Topics API key in the SSM Param Store of the account you deploy to
- Docker
To deploy the project, you need to do the following:
- Clone the repo
- Setup your Momento Topics API Key in the SSM Param Store of the account you want to install into. Use a SecureString type and the param name should be "/dev/pizza/momento-api-key" or change the variable "api_key_in_ssm" in the "variables.tf" file.
- Go to the ordering-backend/terraform project
- Run
terraform init
- run
terraform apply
(and type "yes" when it's done with the plan) - Note the output from the terraform apply is a URL like this: https://1dwy6zvr05.execute-api.us-east-1.amazonaws.com/dev/orders)
- Create a .env file in the ordering-frontend/ directory (i.e. ordering-frontend/.env) with contents similar to the included sample-env file in the ordering-frontend folder.
- In your .env file replace the REACT_APP_ORDERING_API value with the output value from terraform.
- Go to the ordering-backend/containers/fargate_rust_order_delivery directory and run
./create_ecr_and_push.sh
- Go to the ordering-backend/containers/fargate_rust_order_processor directory and run
./create_ecr_and_push.sh
- Change into the ordering-frontend folder
- run
npm install
- run
npm start
- The Cloud Pizzeria shop should be displayed
Run the following terraform command to destroy all the infrastructure.
terraform destroy (from the infra directory)
This repository is associated with the following blog https://darryl-ruggles.cloud/serverless-pizza-ordering