gpt4 book ai didi

aws-step-functions - 如何使用文件中定义的状态机在本地执行 AWS Step Functions?

转载 作者:行者123 更新时间:2023-12-02 16:16:30 32 4
gpt4 key购买 nike

我已按照 AWS 文档中的步骤在本地设置和运行 AWS Step Functions:https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html .

一切正常,但在第 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 Step Functions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66527471/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com