【问题标题】:run locally Step Function defined in a SAM template在 SAM 模板中定义的本地运行 Step Function
【发布时间】:2020-07-05 21:02:05
【问题描述】:

我按照指南 https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html 在本地运行内联定义的 Step Function。

但我没有找到任何指南如何在本地测试定义到 SAM 模板 (template.yaml) 中的 Step Function。

有可能吗?

【问题讨论】:

    标签: aws-step-functions aws-sam aws-sam-cli


    【解决方案1】:

    目前 Step Functions 与 SAM 的集成仍处于早期阶段。它提供来自documentation 的以下功能:

    使用 AWS SAM 示例模板在几分钟内开始使用。

    将您的状态机构建到您的无服务器应用程序中。

    使用变量替换将 ARN 替换到您的状态机中 在部署时。

    使用 AWS SAM 策略简化指定您的状态机角色 模板。

    使用 API Gateway、EventBridge 事件触发状态机执行, 或在您的 AWS SAM 模板中的计划。

    但是,与您可以使用 SAM local 在本地模拟 Lambda 和 API Gateway 不同,您不能使用 SAM 在本地模拟 Step Functions。

    Step Functions Local 是唯一官方支持的在本地测试状态机的方法,与 SAM local 命令配合使用,您可以使用本地版本的 Step Functions 调用本地版本的 AWS Lambda。

    【讨论】:

      【解决方案2】:

      您可以使用所需语言的 SDK 并按照以下文档创建自动化测试:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html

      Node.js 示例:

      const stepfunctions = new AWS.StepFunctions({endpoint: 'http://localhost:8083'});
      

      其他选项是使用带有 bash/sh 文件的 AWS CLI 并创建可以通过“npm run”调用的手动(奇怪)测试,例如:https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html

      $ aws stepfunctions --endpoint http://localhost:8083 <command>
      

      【讨论】:

        猜你喜欢
        • 2021-06-03
        • 2019-08-11
        • 2022-08-23
        • 1970-01-01
        • 2019-04-24
        • 2020-11-30
        • 2021-04-19
        • 2021-09-09
        • 1970-01-01
        相关资源
        最近更新 更多