在本地时 运行 'aws stepfunctions' 如何使用状态机 ASL 文件进行定义

when locally running 'aws stepfunctions' how to use the statemachine ASL file for the definition

在 AWS samaws 环境中,有没有办法使用 SAM 项目中定义的相同 json 文件在本地调用 SAM 步骤函数?

我试图在本地调用 AWS“股票交易”示例中的示例步骤函数,但提供了 .asl.json 文件的 filename 而不是手动重新创建 json(取消引用变量名称)并将其粘贴到命令行。

我有两个必要的 docker 容器 运行,例如

sam local start-lambda

docker run -p 8083:8083 amazon/aws-stepfunctions-local

运行 在单独的 Mac 终端 windows。

step函数在文件中定义statemachine/stock_trader.asl.json

问题是我能找到的 100% 的指南都简单地重复了通过标准输入而不是文件名创建状态机的同一个 AWS 示例。

虽然我找不到任何记录在案的示例,但凭直觉我发现我可以使用 --definition file://PATH/FILE 来提供 json 文件,例如

aws stepfunctions --endpoint http://localhost:8083 create-state-machine \
    --definition file://statemachine/stock_trader.asl.json \
    --name StockTradingStateMachine --role-arn "arn:aws:iam::012345678901:role/DummyRole"

但是,那(自然地)只是插入文字 json 文件...例如,使用变量名称 "Resource": "${StockCheckerFunctionArn}" 而不是资源的本地 ARN。

有什么方法可以取消引用 json 文件中的变量名吗?或者我们必须手动创建(和维护)重复的 json 文件,并为每个引用的资源手动替换“本地”ARN?

我希望出现更好的解决方案,但这是我目前所做的...

我在 Bash 脚本中调用状态机,该脚本调用 sed 手动将通用模板重新写入 json 文件,其中的参数替换为 bash 中指定的值] 剧本

这是一个单变量的小例子:

$template_source=template.json 
$sm_actual=ready_to_use.json # a "runable" tmp file with placeholders replaced with actual variable names
$sm_function_tag=REPLACEMENT_TEXT
$sm_name=MyFunctionName
$sm_arn=arn:aws:states:us-east-1:MYACCOUNT:stateMachine:$sm_name

# THIS creates the de-referenced json file
# (can have 5 -e params if replacing 5 placeholders)
sed -e "s/REPLACEME/$sm_function_tag/"  ./statemachine/$template_source > ./statemachine/$sm_actual  || exit 2

# THIS copies the file into a bash variable 
json_text=$(cat ./statemachine/$sm_actual)

# This supplies the de-referenced json file contents to the `--definition` parameter:
aws stepfunctions CMD-INVOKE-UPLOAD-WHATEVER \
  --no-cli-pager \
  --state-machine-arn $sm_arn \
  --role-arn  $sm_role_arn \
  --definition "$json_text" \
  --profile AWS-PROFILE-TO-USE || exit 2