启动StepFunction并退出不会触发执行 [英] Starting a StepFunction and exiting doesn't trigger execution

查看:163
本文介绍了启动StepFunction并退出不会触发执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Lambda函数tranportKickoff,该函数接收输入,然后将输入/代理发送给 Step Function . 下面的代码可以运行,并且没有出现任何错误,但同时step函数未执行.

I have Lambda function tranportKickoff which receives an input and then sends/proxies that input forward into a Step Function. The code below does run and I am getting no errors but at the same time the step function is NOT executing.

对于设计也很关键,我不希望transportKickoff函数等待step函数完成,因为它可能需要很长时间才能运行.但是,我期望Step Function的 calling 中的任何错误都将被同步报告.也许这种想法是错误的,我不知何故错过了某个地方抛出的错误.但是,如果是这种情况,我想找到一种方法,该方法能够实现在Step Function开始执行后立即退出启动lambda函数的目标.

Also critical to the design, I do not want the transportKickoff function to wait around for the step function to complete as it can be quite long running. I was, however, expecting that any errors in the calling of the Step Function would be reported back synchronously. Maybe this thought is at fault and I'm somehow missing out on an error that is thrown somewhere. If that's the case, however, I'd like to find a way which is able to achieve the goal of having the kickoff lambda function exit as soon as the Step Function has started execution.

注意:我可以独立执行step函数,并且我知道它可以正常工作

note: I can execute the step function independently and I know that it works correctly

  const stepFn = new StepFunctions({ apiVersion: "2016-11-23" });
  const stage = process.env.AWS_STAGE;
  const name = `transport-steps ${message.command} for "${stage}" environment at ${Date.now()}`;
  const params: StepFunctions.StartExecutionInput = {
    stateMachineArn: `arn:aws:states:us-east-1:999999999:stateMachine:transportion-${stage}-steps`,
    input: JSON.stringify(message),
    name
  };
  const request = stepFn.startExecution(params);
  request.send();
  console.info(
    `startExecution request for step function was sent, context sent was:\n`,
    JSON.stringify(params, null, 2)
  );

  callback(null, {
    statusCode: 200
  });

我还从控制台检查了我是否具有开始执行步进功能的正确权限:

I have also checked from the console that I have what I believe to be the right permissions to start the execution of a step function:

我现在添加了更多权限(见下文),但仍然遇到相同的问题:

I've now added more permissions (see below) but still experiencing the same problem:

  • 'states:ListStateMachines'
  • 州:CreateActivity"
  • 状态:开始执行"
  • 州:ListExecutions"
  • 'states:DescribeExecution'
  • 州:DescribeStateMachineForExecution"
  • 'states:GetExecutionHistory'

推荐答案

好,我自己已经弄清楚了,希望这个答案对其他人有帮助.

Ok I have figured this one out myself, hopefully this answer will be helpful for others:

首先,send()方法不是同步调用,但也不返回promise.相反,必须在发送之前在Request对象上设置侦听器,以便可以适当地响应成功/失败状态.

First of all, the send() method is not a synchronous call but it does not return a promise either. Instead you must setup listeners on the Request object before sending so that you can appropriate respond to success/failure states.

我已使用以下代码完成了此操作:

I've done this with the following code:

const stepFn = new StepFunctions({ apiVersion: "2016-11-23" });
const stage = process.env.AWS_STAGE;
const name = `${message.command}-${message.upc}-${message.accountName}-${stage}-${Date.now()}`;
const params: StepFunctions.StartExecutionInput = {
  stateMachineArn: `arn:aws:states:us-east-1:837955377040:stateMachine:transportation-${stage}-steps`,
  input: JSON.stringify(message),
  name
};
const request = stepFn.startExecution(params);
// listen for success
request.on("extractData", req => {
  console.info(
    `startExecution request for step function was sent and validated, context sent was:\n`,
    JSON.stringify(params, null, 2)
  );

  callback(null, {
    statusCode: 200
  });
});
// listen for error
request.on("error", (err, response) => {
  console.warn(
    `There was an error --  ${err.message} [${err.code}, ${
      err.statusCode
    }] -- that blocked the kickoff of the ${message.command} ITMS command for ${
      message.upc
    } UPC, ${message.accountName} account.`
  );
  callback(err.statusCode, {
    message: err.message,
    errors: [err]
  });
});
// send request
request.send();

现在请记住,有一个成功"事件,但是我使用"extractData"来捕获成功,因为我想尽快获得响应.成功可能同样会奏效,但是从Typescript类型中查看该语言并不清楚,在我的测试中,我确定"extractData"方法确实可以正常工作.

Now please bear in mind there is a "success" event but I used "extractData" to capture success as I wanted to get a response as quickly as possible. It's possible that success would have worked equally as well but looking at the language in the Typescript typings it wasn't entirely clear and in my testing I'm certain that the "extractData" method does work as expected.

至于为什么我的步进函数没有得到任何执行...必须以我命名函数的方式...您只能使用名称中的一部分字符,所以我跨步了这种限制,但直到我能够使用上面的代码捕获错误后才意识到.

As for why I was not getting any execution on my step functions ... it had to the way I was naming the function ... you're limited to a subset of characters in the name and I'd stepped over that restriction but didn't realize until I was able to capture the error with the code above.

这篇关于启动StepFunction并退出不会触发执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆