如何使用文件中定义的状态计算机在本地执行AWS步骤函数? 我遵循了AWS文档的步骤,以便在本地设置并运行AWS步骤功能:https://docs.aws.amazon.com/step-functions/latest/dg/dg/sfn-local-lambda。 html。 一切都很好,...

问题描述 投票:0回答:2
所有功能都很好,但是在第5步中,它说您必须创建一台状态机,并且使用命令行执行此操作可能会很痛苦,而当定义包含许多任务时。

有任何方法可以启动在本地.ASL文件中定义的状态机的执行? 这是我本地定义的状态机的一个示例(来自模板):

{ "Comment": "A state machine that does mock stock trading.", "StartAt": "Check Stock Value", "States": { "Check Stock Value": { "Type": "Task", "Resource": "${StockCheckerFunctionArn}", "Retry": [ { "ErrorEquals": [ "States.TaskFailed" ], "IntervalSeconds": 15, "MaxAttempts": 5, "BackoffRate": 1.5 } ], "Next": "Buy or Sell?" }, "Buy or Sell?": { "Type": "Choice", "Choices": [ { "Variable": "$.stock_price", "NumericLessThanEquals": 50, "Next": "Buy Stock" } ], "Default": "Sell Stock" }, "Sell Stock": { "Type": "Task", "Resource": "${StockSellerFunctionArn}", "Retry": [ { "ErrorEquals": [ "States.TaskFailed" ], "IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 1 } ], "Next": "Record Transaction" }, "Buy Stock": { "Type": "Task", "Resource": "${StockBuyerFunctionArn}", "Retry": [ { "ErrorEquals": [ "States.TaskFailed" ], "IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 1 } ], "Next": "Record Transaction" }, "Record Transaction": { "Type": "Task", "Resource": "${DDBPutItem}", "Parameters": { "TableName": "${DDBTable}", "Item": { "Id": { "S.$": "$.id" }, "Type": { "S.$": "$.type" }, "Price": { "N.$": "$.price" }, "Quantity": { "N.$": "$.qty" }, "Timestamp": { "S.$": "$.timestamp" } } }, "Retry": [ { "ErrorEquals": [ "States.TaskFailed" ], "IntervalSeconds": 20, "MaxAttempts": 5, "BackoffRate": 10 } ], "End": true } } }

您可以使用

cat
将文件读为字符串。
aws stepfunctions --endpoint http://localhost:8083 create-state-machine --definition "$(cat local.asl.json)" --name "HelloWorld" --role-arn "arn:aws:iam::012345678901:role/DummyRole"
aws-step-functions aws-sam aws-sam-cli
2个回答
6
投票

使用命令替代:

aws stepfunctions --endpoint http://localhost:8083 create-state-machine \ --definition "$(< local.asl.json)" \ --name "HelloWorld" \ --role-arn "arn:aws:iam::012345678901:role/DummyRole";
要了解更多信息,在

0
投票
中搜索

man bash;

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.