【问题标题】:Why Does My Lambda Function Not `startExecution` My Step Function为什么我的 Lambda 函数不是 `startExecution` 我的 Step Function
【发布时间】:2022-10-06 18:02:52
【问题描述】:

我希望将我的 Lambda 与我的 Step Function 连接起来,但无法弄清楚为什么它不会 startExecution。

开发工具包代码:

import AWS from "aws-sdk";
const stepfunctions = new AWS.StepFunctions({ apiVersion: "2016-11-23" });
interface Params {
  stateMachineArn: string;
  input: string;
}

export async function handler(event: any, context: object) {
  console.log("event.body", event.body);

  const params: Params = {
    stateMachineArn: process.env.STEP_FUNCTION_ARN,
    input: JSON.stringify(event.body),
    name: "testNameField",
  };

  console.log("PARAMS", params);

  stepfunctions.startExecution(params, (err: any, data: any) => {
    if (err) {
      console.log("THERE WAS AN ERROR", err);
      console.log("ERROR STACK", err.stack);
    } // an error occurred
    else {
      console.log("data", data);
    } // successful response
  });
}

权限:

Allow: states:DeleteStateMachine
Allow: states:StartExecution
Allow: states:CreateStateMachine
Allow: states:SendTaskSuccess
Allow: states:DeleteActivity
Allow: states:SendTaskHeartbeat
Allow: states:CreateActivity
Allow: states:SendTaskFailure
Allow: states:StopExecution
Allow: states:GetActivityTask
Allow: states:UpdateStateMachine
Allow: states:StartSyncExecution

额外的信息:

  1. 我已尝试在控制台上对 lambda 函数进行“测试”, 它从中成功。我不知道还能去哪里看。
  2. 在 step 函数中,所有列 (总计/正在运行/成功/失败/超时/中止)为 0。
  3. 参数console.log 提供了正确的信息

【问题讨论】:

    标签: amazon-web-services lambda aws-step-functions


    【解决方案1】:

    console.log 是否有任何错误信息输出?

    【讨论】:

      【解决方案2】:

      解决方案代码:

      const AWS = require("aws-sdk");
      AWS.config.update({ region: "eu-west-1" });
      const stepFunction = new AWS.StepFunctions();
      interface Params {
        stateMachineArn: string;
        input: string;
        name: string;
      }
      exports.handler = async (event: any) => {
        console.log(event);
        const stepFunctionParams = {
          stateMachineArn: process.env.STEP_FUNCTION_ARN,
          input: JSON.stringify({
            message: event.body,
          }),
          name: "name" + String(Date.now()),
        };
        try {
          const stepFunctionResponse = await stepFunction
            .startExecution(stepFunctionParams)
            .promise();
          return { statusCode: 200, body: "Success" };
        } catch (e) {
          console.log("Problem executing SF :", JSON.stringify(e));
          return {
            statusCode: 500,
            body: "Problem executing step function : " + JSON.stringify(e),
            headers: { "Access-Control-Allow-Origin": "*" },
          };
        }
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-17
        • 2017-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-14
        • 2021-12-15
        相关资源
        最近更新 更多