簡體   English   中英

為什么我的 Lambda Function 不是 `startExecution` 我的步驟 Function

[英]Why Does My Lambda Function Not `startExecution` My Step Function

我希望將我的 Lambda 與我的步驟 Function 連接起來,但無法弄清楚為什么它不會startExecution

SDK 代碼:

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 function 進行“測試”,它成功了。 我不確定還有什么地方可以看。
  2. 在步驟function中,所有的列(Total/Running/Succeeded/Failed/Timed out/Aborted)都是0。
  3. params console.log提供了正確的信息

console.log 是否有錯誤信息輸出?

解決方案代碼:

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": "*" },
    };
  }
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM