{
"Comment": "Item crafting pipeline — validates player account and recipe availability, forges the item using required materials, then generates lore text via Bedrock.",
"StartAt": "ValidateAccount",
"States": {
"ValidateAccount": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "${ValidateAccountFunctionArn}",
"Payload.$": "$"
},
"ResultSelector": {
"isValid.$": "$.Payload.isValid",
"isBanned.$": "$.Payload.isBanned",
"playerId.$": "$.Payload.playerId",
"username.$": "$.Payload.username",
"platform.$": "$.Payload.platform"
},
"ResultPath": "$.accountValidation",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 3,
"BackoffRate": 2.0
}
],
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"ResultPath": "$.error",
"Next": "ValidationFailed"
}
],
"Next": "IsAccountValid"
},
"IsAccountValid": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.accountValidation.isValid",
"BooleanEquals": false,
"Next": "ValidationFailed"
}
],
"Default": "ValidateCraftingRecipe"
},
"ValidationFailed": {
"Type": "Fail",
"Error": "ValidationFailed",
"Cause": "Account validation failed or account is banned"
},
"ValidateCraftingRecipe": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "${ValidateCraftingRecipeFunctionArn}",
"Payload": {
"playerId.$": "$.accountValidation.playerId",
"recipeId.$": "$.recipeId",
"craftingLevel.$": "$.craftingLevel",
"inventory.$": "$.inventory"
}
},
"ResultSelector": {
"isValid.$": "$.Payload.isValid",
"recipeId.$": "$.Payload.recipeId",
"recipe.$": "$.Payload.recipe",
"missingMaterials.$": "$.Payload.missingMaterials",
"reason.$": "$.Payload.reason"
},
"ResultPath": "$.recipeValidation",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 3,
"BackoffRate": 2.0
}
],
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"ResultPath": "$.error",
"Next": "RecipeValidationFailed"
}
],
"Next": "IsRecipeValid"
},
"IsRecipeValid": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.recipeValidation.isValid",
"BooleanEquals": false,
"Next": "RecipeValidationFailed"
}
],
"Default": "ForgeItem"
},
"RecipeValidationFailed": {
"Type": "Fail",
"Error": "RecipeValidationFailed",
"Cause": "Recipe not found, level too low, or required materials missing"
},
"ForgeItem": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "${ForgeItemFunctionArn}",
"Payload": {
"playerId.$": "$.accountValidation.playerId",
"recipe.$": "$.recipeValidation.recipe"
}
},
"ResultSelector": {
"forgeId.$": "$.Payload.forgeId",
"itemId.$": "$.Payload.itemId",
"itemName.$": "$.Payload.itemName",
"itemType.$": "$.Payload.itemType",
"rarity.$": "$.Payload.rarity",
"materialsConsumed.$": "$.Payload.materialsConsumed",
"forgedAt.$": "$.Payload.forgedAt"
},
"ResultPath": "$.forgeResult",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 3,
"BackoffRate": 2.0
}
],
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"ResultPath": "$.error",
"Next": "ForgeFailed"
}
],
"Next": "GenerateItemLore"
},
"ForgeFailed": {
"Type": "Fail",
"Error": "ForgeFailed",
"Cause": "Item forging process failed"
},
"GenerateItemLore": {
"Type": "Task",
"Resource": "arn:aws:states:::bedrock:invokeModel",
"Parameters": {
"ModelId": "anthropic.claude-3-5-sonnet-20241022-v2:0",
"Body": {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 200,
"messages": [
{
"role": "user",
"content.$": "States.Format('Write a short fantasy item description (2-3 sentences) for a {} rarity item called \"{}\". The item is classified as a {}. Make it sound legendary and immersive, as if it belongs in a high fantasy game world.', $.forgeResult.rarity, $.forgeResult.itemName, $.forgeResult.itemType)"
}
]
}
},
"ResultSelector": {
"loreText.$": "$.Body.content[0].text"
},
"ResultPath": "$.itemLore",
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"ResultPath": "$.itemLore",
"Next": "CraftingComplete"
}
],
"Next": "CraftingComplete"
},
"CraftingComplete": {
"Type": "Succeed"
}
}
}JSONGaming teams can use patterns like this to build reliable, compliant, and scalable automation for payment systems and can test and refine these flows locally with Thrubit to reduce cloud cost and speed up iteration.