从 java lambda 调用 aws Step 函数
Invoking aws Step function from java lambda
我在 aws 中创建了一个步骤函数。我的状态机名称是 '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 调用它时,应该触发步进函数并工作...
很高兴地通知您,我找到了解决方案。我提到的上述代码用于创建一个新的状态机并尝试从 java lambda 运行 新创建的状态机。对于我只是调用已经在 aws step function 中创建的 step function 的场景,请按照以下步骤操作。
首先,
在 pom.xml
中添加依赖项
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-stepfunctions</artifactId>
<version>1.11.285</version>
然后使用下面的代码从您的 java
中调用步进函数
awsStepfunctionClient.startExecution(StartExecutionRequest);
对于 AWS Java SDK v2,pom 的依赖项是:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sfn</artifactId>
<version>2.16.59</version>
<dependency>
然后使用客户端的标准构建器模式(和 StartExecutionRequest 对象)来触发您的执行:
SfnClient sfc = SfnClient.builder()
.region()
.build();
sfc.startExecution(startExecutionRequest);
我在 aws 中创建了一个步骤函数。我的状态机名称是 '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 调用它时,应该触发步进函数并工作...
很高兴地通知您,我找到了解决方案。我提到的上述代码用于创建一个新的状态机并尝试从 java lambda 运行 新创建的状态机。对于我只是调用已经在 aws step function 中创建的 step function 的场景,请按照以下步骤操作。
首先, 在 pom.xml
中添加依赖项<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-stepfunctions</artifactId>
<version>1.11.285</version>
然后使用下面的代码从您的 java
中调用步进函数 awsStepfunctionClient.startExecution(StartExecutionRequest);
对于 AWS Java SDK v2,pom 的依赖项是:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sfn</artifactId>
<version>2.16.59</version>
<dependency>
然后使用客户端的标准构建器模式(和 StartExecutionRequest 对象)来触发您的执行:
SfnClient sfc = SfnClient.builder()
.region()
.build();
sfc.startExecution(startExecutionRequest);