aws-samples / serverless-coffee-workshop

This is the repo for Serverlesspresso workshop. Questions? Contact @jbesw or @benjamin_l_s on GitHub or Twitter.
https://workshop.serverlesscoffee.com/
MIT No Attribution
95 stars 63 forks source link

This version of code is different compared to workshop #61

Closed yogaics closed 3 months ago

yogaics commented 3 months ago

Hi, so this version of git is different compared to the workshop. Especially since in workshop is using s3 bucket as the source. This is what I noticeably found:

  1. Display is different between this git and https://workshop-display.serverlesscoffee.com/
  2. In frontend barista app, there's no Printing.vue, makes deployment for barista app error

Also when I deploy cloudformation yaml from the workshop: https://ws-assets-prod-iad-r-iad-ed304a55c2ca1aee.s3.us-east-1.amazonaws.com/28e7066a-b0bb-42ad-a0e9-8e8eeeb51133/workshop-self-service.yaml, I get step function error while trying to order.

Error is in Update Order. This is the error: The conditional request failed (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ConditionalCheckFailedException; Request ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Proxy: null)

bfreiberg commented 3 months ago

Hi @yogaics , thanks for creating this issue. Let me focus on the error for now.

It would be great if you could share exactly when the error is raised. How did you order, via the UI or as part of the testing? Could you share the definition of the state machine.

yogaics commented 3 months ago

Hi @bfreiberg,

So this is what I do:

  1. Deploy the yaml using link from the workshop in Singapore region
  2. Setup the display add userpoolwebclientid and poolid
  3. Scan for the qr to order using display app
  4. On app, order is success, but it doesn't show in barista display
  5. Check for state machine, and got the error. Screenshot 2024-06-13 134736

this is my current state machine definition: { "Comment": "A description of my state machine", "StartAt": "Decide Action", "States": { "Decide Action": { "Type": "Choice", "Choices": [ { "Variable": "$.action", "StringEquals": "complete", "Next": "Complete Order" }, { "Variable": "$.action", "StringEquals": "cancel", "Next": "Cancel Order" }, { "Variable": "$.action", "StringEquals": "make", "Next": "Claim Order" }, { "Variable": "$.action", "StringEquals": "unmake", "Next": "Claim Order" } ], "Default": "Customer Put Order" }, "Cancel Order": { "Type": "Pass", "Next": "DynamoDB Update Order Record", "Result": { "state": "Cancelled" }, "ResultPath": "$.result" }, "DynamoDB Update Order Record": { "Type": "Task", "Resource": "arn:aws:states:::dynamodb:updateItem", "Parameters": { "TableName": "serverlesspresso-order-table", "Key": { "PK": { "S": "orders" }, "SK": { "S.$": "$.orderId" } }, "UpdateExpression": "set #OS = :OS", "ExpressionAttributeNames": { "#OS": "ORDERSTATE" }, "ExpressionAttributeValues": { ":OS": { "S.$": "$.result.state" } }, "ReturnValues": "ALL_NEW" }, "ResultPath": "$.result", "Next": "Construct record (1)", "ResultSelector": { "Attributes.$": "$.Attributes" } }, "Construct record (1)": { "Type": "Pass", "Next": "Emit Completed || Cancelled", "ResultPath": "$.detail", "Parameters": { "orderId.$": "$.orderId", "userId.$": "$.result.Attributes.USERID.S", "ORDERSTATE.$": "$.result.Attributes.ORDERSTATE.S", "Message": "Barrista has cancelled or completed teh order" } }, "Emit Completed || Cancelled": { "Type": "Task", "Resource": "arn:aws:states:::events:putEvents", "Parameters": { "Entries": [ { "Detail.$": "States.JsonToString($.detail)", "DetailType.$": "States.Format('OrderManager.Order{}', $.detail.ORDERSTATE)", "EventBusName": "Serverlesspresso", "Source": "awsserverlessda.serverlesspresso", "Time.$": "$$.State.EnteredTime" } ] }, "Next": "Resume Order Processor 1", "ResultPath": "$.eventEmit" }, "Complete Order": { "Type": "Pass", "Next": "DynamoDB Update Order Record", "Result": { "state": "Completed" }, "ResultPath": "$.result" }, "Customer Put Order": { "Type": "Pass", "Next": "get menu" }, "get menu": { "Type": "Task", "Resource": "arn:aws:states:::dynamodb:getItem", "Parameters": { "TableName": "serverlesspresso-config-table", "Key": { "PK": { "S": "menu" } } }, "Next": "Sanitize order", "ResultPath": "$.menu" }, "Sanitize order": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { "Payload.$": "$", "FunctionName": "serverlesspresso-SanitizeOrderLambda-2RMFTv2WMX5J" }, "Retry": [ { "ErrorEquals": [ "Lambda.ServiceException", "Lambda.AWSLambdaException", "Lambda.SdkClientException" ], "IntervalSeconds": 2, "MaxAttempts": 6, "BackoffRate": 2 } ], "Next": "Is Order Valid?", "ResultPath": "$.sanitise" }, "Is Order Valid?": { "Type": "Choice", "Choices": [ { "Variable": "$.sanitise.Payload", "BooleanEquals": false, "Next": "not a valid order" } ], "Default": "Update order" }, "not a valid order": { "Type": "Succeed" }, "Update order": { "Type": "Task", "Resource": "arn:aws:states:::dynamodb:updateItem", "Parameters": { "TableName": "serverlesspresso-order-table", "Key": { "PK": { "S": "orders" }, "SK": { "S.$": "$.orderId" } }, "UpdateExpression": "set #drinkOrder = :drinkOrder", "ConditionExpression": "#userId = :userId AND attribute_exists(TaskToken)", "ExpressionAttributeNames": { "#drinkOrder": "drinkOrder", "#userId": "USERID" }, "ExpressionAttributeValues": { ":drinkOrder": { "S.$": "States.JsonToString($.body)" }, ":userId": { "S.$": "$.body.userId" } }, "ReturnValues": "ALL_NEW" }, "Next": "Resume Order Processor 2", "ResultSelector": { "TaskToken.$": "$.Attributes.TaskToken.S" }, "OutputPath": "$.record", "ResultPath": "$.record" }, "Resume Order Processor 1": { "Type": "Task", "Parameters": { "Output": "{}", "TaskToken.$": "$.result.Attributes.TaskToken.S" }, "Resource": "arn:aws:states:::aws-sdk:sfn:sendTaskSuccess", "End": true }, "Resume Order Processor 2": { "Type": "Task", "Parameters": { "Output": "{}", "TaskToken.$": "$.TaskToken" }, "Resource": "arn:aws:states:::aws-sdk:sfn:sendTaskSuccess", "End": true }, "Claim Order": { "Type": "Pass", "Next": "Make OR Unmake?" }, "Make OR Unmake?": { "Type": "Choice", "Choices": [ { "Variable": "$.action", "StringEquals": "unmake", "Next": "Unmake Order" }, { "Variable": "$.action", "StringEquals": "make", "Next": "DynamoDB Update Order" } ], "Default": "DynamoDB Update Order" }, "Unmake Order": { "Type": "Pass", "Parameters": { "baristaUserId": "", "orderId.$": "$.orderId", "Message": "The barista has pressed the 'UnMake order' button, this Invokes a Lambda function via API Gateway, which updates the order in DynamoDB and emits a new 'make order' Event." }, "Next": "DynamoDB Update Order" }, "DynamoDB Update Order": { "Type": "Task", "Resource": "arn:aws:states:::dynamodb:updateItem", "Parameters": { "TableName": "serverlesspresso-order-table", "Key": { "PK": { "S": "orders" }, "SK": { "S.$": "$.orderId" } }, "UpdateExpression": "set #baristaUserId = :baristaUserId", "ExpressionAttributeNames": { "#baristaUserId": "baristaUserId" }, "ExpressionAttributeValues": { ":baristaUserId": { "S.$": "$.baristaUserId" } }, "ReturnValues": "ALL_NEW" }, "ResultSelector": { "Attributes.$": "$.Attributes" }, "ResultPath": "$.result", "Next": "Construct record" }, "Construct record": { "Type": "Pass", "Next": "EventBridge Emit Making Order", "ResultPath": "$.detail", "Parameters": { "baristaUserId.$": "$.result.Attributes.baristaUserId.S", "orderId.$": "$.orderId", "userId.$": "$.result.Attributes.USERID.S", "Message": "The barista has pressed the 'Make order' button, this Invokes a Lambda function via API Gateway, which updates the order in DynamoDB and emits a new 'make order' Event." } }, "EventBridge Emit Making Order": { "Type": "Task", "Resource": "arn:aws:states:::events:putEvents", "Parameters": { "Entries": [ { "Detail.$": "States.JsonToString($.detail)", "DetailType": "OrderManager.MakeOrder", "EventBusName": "Serverlesspresso", "Source": "awsserverlessda.serverlesspresso", "Time.$": "$$.State.EnteredTime" } ] }, "End": true } } }

bfreiberg commented 3 months ago

Thanks. This error happens if there was no order number created in the DynamoDB table. Can you check the executions of the OrderManagerWorkflow state machine for errors?

yogaics commented 3 months ago

Looks like I've miss some things in the OrderProcessWorkflow. Now it's working fine. Thank you.