【问题标题】:How to trigger AWS step function from aws lambda如何从 aws lambda 触发 AWS 步进函数
【发布时间】:2019-08-23 20:33:41
【问题描述】:

我需要从 lambda 处理程序(用 java 编写)触发一个步进函数。 Lambda 可以通过 IAM 完全访问 AWS 步骤函数。

我已经尝试了以下,我没有看到错误,我得到了 200 Json,但是 step 函数没有执行。

这是我试过的代码:

StartExecutionRequest startExecutionRequest = new StartExecutionRequest();
startExecutionRequest.setStateMachineArn(stateMachineArn);
logger.info("stateMachineArn: "+stateMachineArn);
logger.info("stateMachineInputJson: "+stateMachineInputJson.toString());

AWSStepFunctionsAsync client = AWSStepFunctionsAsyncClientBuilder.defaultClient();
logger.info("startExecutionRequest: "+startExecutionRequest);
try {
    logger.info("startExecutionAsync now");
    client.startExecutionAsync(startExecutionRequest);
    logger.info("startExecutionAsync done");
    return new Response(200,"","stepFunctionTriggered");
} 
catch (Exception e) {
    logger.error("Exception while starting execution:"+ e);
    return  new Response(400,"","Error occured while executing Step Function");
}

Lambda 日志:

START RequestId: 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56 Version: $LATEST
2019-04-02 18:17:56 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56 INFO  LaunchStepFunction:39 - stateMachineArn: arn:aws:states:xxxxx
2019-04-02 18:17:56 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56 INFO  LaunchStepFunction:40 - stateMachineInputJson: {}
2019-04-02 18:18:01 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56 INFO  LaunchStepFunction:43 - startExecutionRequest: {StateMachineArn: arn:aws:states:us-east-1:xxx:stateMachine:xxxx,}
2019-04-02 18:18:01 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56 INFO  LaunchStepFunction:45 - startExecutionAsync now
2019-04-02 18:18:01 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56 INFO  LaunchStepFunction:47 - startExecutionAsync done
END RequestId: 2c6ac51d-1262-4fbf-acdc-ce706d5fbe56

【问题讨论】:

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


    【解决方案1】:

    我想通了。

    AWSStepFunctionsAsyncClient 需要使用 clientConfig 和正确的区域构建。对我们来说是 US-EAST-1。奇怪的是,当我们不这样做并且什么也没有发生时,没有例外。也就是说,而不是

    AWSStepFunctionsAsync client = AWSStepFunctionsAsyncClientBuilder.defaultClient();
    

    我们应该使用:

    AWSStepFunctionsAsyncClientBuilder.standard()
                .withClientConfiguration(new ClientConfiguration())
                .withRegion(Regions.US_EAST_1)
                .build();
    

    之后,我遇到了 HTTP 连接超时问题。为了解决这个问题,已修复 lambda 的出口规则,以便它可以在 VPC 外部通过 Internet 向 step 函数端点发起 HTTP 调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 2018-10-10
      • 2018-01-15
      • 1970-01-01
      • 2016-04-19
      • 1970-01-01
      • 2016-10-19
      相关资源
      最近更新 更多