This application will create a State Machine, an SNS topic, an SQS Queue, ApiGateway, Lambda, and a DynamoDB Table. The Frontend web app will submit order to State Machine via ApiGateway as proxy to Lambda. This will create the order in DynamoDB and place pick order in SQS for employee. After order is picked the TaskToken callback is sent with a success. The customer is sent a message via SNS that their order is ready for pickup. When the customer arrives they send a TaskToken back with success and their current parking location. Employees are alerted the customer has arrived via SNS message. The employee will send TaskToken success on completion of order delivery.
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- AWS Serverless Application Model (AWS SAM) installed
-
Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/step-functions-workflows-collection
-
Change directory to the pattern directory:
cd ./curbside-pickup
-
From the command line, use AWS SAM to deploy the AWS resources for the workflow as specified in the template.yaml file:
sam build && sam deploy --guided
-
During the prompts:
- Enter a stack name
- Enter the desired AWS Region
- Enter Email for SNS Notification delivery
- Allow SAM CLI to create IAM roles with the required permissions.
- APIProxy may not have authorization defined, Is this okay? Enter
YES
Once you have run
sam deploy --guided
mode once and saved arguments to a configuration file (samconfig.toml), you can usesam deploy
in future to use these defaults. -
Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
- This App starts by submitting a JSON order payload (Frontend) to ApiGateway via Lambda proxy and starts a State Machine execution.
- The State Machine creates the order in DynamoDB and then sends a pick order message to SQS with a Task Token callback.
- A process pulls the pick order message from SQS (Lambda) and displays to employee (frontend).
- The employee will pick the order and send back Task Token
complete:true
to State Machine via ApiGateway Lambda proxy (Frontend). - The State Machine will then Update Order Status in DynamoDB and send the Customer a
ready-pickup
notification message via SNS with Task Token Callback. - The customer will click URL in message that will direct them to Frontend where they can enter their parking location and send back Task Token
complete:true, location:STRING
to State Machine via ApiGateway Lambda proxy - The State Machine will then update Status in DynamoDB and send store employees
customer-arrived
notification message via SNS with Task Token Callback. - Employee will check the frontend for order details and deliver order to customer location.
- Employee will send back Task Token
complete:true
to State Machine via ApiGateway Lambda proxy (Frontend) when transaction is complete. - State Machine will update the Status of order to
complete
- After deployment you will receive an email titled
AWS Notification - Subscription Confirmation
. Click on the link in the email to confirm your subscription. This will allow SNS to send you emails. - All interaction will happen through frontend React Application. Change directory to:
cd ./curbside-pickup/frontend
- Update React Environmental Variable file
.env.local
with ApiGateway URL Endpoint from sam deploy OutputsApiEndpointURL
. Example below:REACT_APP_BASE_API_URI="https://YOUR-URI.execute-api.us-west-2.amazonaws.com/Prod/"
- Install package dependencies and start application
npm i npm start
- Create your first test order from React App at http://localhost:3000/
- Navigate to the AWS Step Functions console and select the
CurbsidePickup
workflow then click on you first execution. If you don't see it, make sure you are in the correct Region. This is where you can see the State Machine move from task to task as you interact with the frontend app. - Navigate to http://localhost:3000/pick-order/ and select a record to act on. Submit desired Status change and observe State Machine Console changes.
- The customer will now receive a message from SNS with a link
http://localhost:3000/arrival/?SOMTHING-HERE
that contains the order ID and Task Token. Navigate to the link and input Parking Location and Submit - The State Machine will send a notification to store employees that the customer has arrived via SNS.
- Navigate to http://localhost:3000/deliver to select the record and complete the order by submitting back the Task Token.
- Congratulations! You have completed the entire happy path. Go ahead and repeat the process but try canceling an order or not being able to locate an item.
- Delete the stack
sam delete
- Confirm the stack has been deleted
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0