从java lambda调用aws Step函数

问题描述 投票:4回答:1

我在aws中创建了一个step函数。我的状态机的名称是'TestStep'。用于迭代1到1000之间的数字。

我创建了一个具有“AWSStepFunctionsFullAccess”策略的IAM角色。

我创建了一个java lambda来访问这个步骤函数。我的代码如下。

 final StateMachine stateMachine = stateMachine().comment("Iterator State Machine Example").startAt("ConfigureCount")
             .state("ConfigureCount", taskState()
               .resource("arn:aws:lambda:us-east-1:ACCOUNTID:function:TestStep")
               .transition(end()))
       .build();
final AWSStepFunctions client = AWSStepFunctionsClientBuilder.defaultClient();
        client.createStateMachine(new CreateStateMachineRequest()
                                                  .withName("TestStep")
                                                  .withRoleArn("arn:aws:iam::ACCOUNTID:role/ROLENAME")
                                                  .withDefinition(stateMachine));

但我收到如下错误。请帮我正确理解。当我从java调用它时,应该触发step函数并且工作...

enter image description here

amazon-web-services aws-lambda aws-step-functions
1个回答
3
投票

很高兴地通知您,我找到了解决方案。我提到的上面的代码是用于创建一个新的状态机并尝试从java lambda运行新创建的状态机。对于我刚刚调用已在aws步骤函数中创建的步骤函数的场景,请按照以下步骤操作。

首先,在pom.xml中添加依赖项

<dependency>
   <groupId>com.amazonaws</groupId>
   <artifactId>aws-java-sdk-stepfunctions</artifactId>
   <version>1.11.285</version>

然后使用下面的代码从java调用step函数

  awsStepfunctionClient.startExecution(StartExecutionRequest);
© www.soinside.com 2019 - 2024. All rights reserved.