Closed yogaics closed 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.
Hi @bfreiberg,
So this is what I do:
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 } } }
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?
Looks like I've miss some things in the OrderProcessWorkflow. Now it's working fine. Thank you.
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:
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)