[英]Invoking aws Step function from java lambda
I have created a step function in aws.我在 aws 中创建了一个步骤函数。 Name of my state machine is 'TestStep'.
我的状态机的名称是“TestStep”。 which is used to iterate a number from 1 to 1000.
它用于迭代从 1 到 1000 的数字。
I have created an IAM Role which has "AWSStepFunctionsFullAccess" policy.我创建了一个具有“AWSStepFunctionsFullAccess”策略的 IAM 角色。
I created one java lambda to access this step function.我创建了一个 java lambda 来访问这个 step 函数。 My code is given below.
我的代码如下。
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));
But I am getting an error like below.但我收到如下错误。 Please help me to get this correctly.
请帮我正确地得到这个。 When i am calling it from java the step function should be triggered and work...
当我从 java 调用它时,应该触发 step 函数并工作...
Happy to inform you that I found the solution.很高兴地通知您,我找到了解决方案。 The above code I mentioned is for creating a new state machine and trying to run the newly created state machine from java lambda.
我上面提到的代码是用于创建一个新的状态机并尝试从 java lambda 运行新创建的状态机。 For my scenario that is just call a step function which is already created in aws step function please follow the below steps.
对于我的场景,它只是调用已经在 aws step function 中创建的 step 函数,请按照以下步骤操作。
First, add dependency in pom.xml首先在pom.xml中添加依赖
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-stepfunctions</artifactId>
<version>1.11.285</version>
then use the below code to call a step function from your java然后使用下面的代码从你的java调用一个步骤函数
awsStepfunctionClient.startExecution(StartExecutionRequest);
For the AWS Java SDK v2, the dependency for the pom is:对于 AWS Java SDK v2,pom 的依赖项是:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sfn</artifactId>
<version>2.16.59</version>
<dependency>
Then use the standard builder pattern for the client (and StartExecutionRequest object) to trigger your execution:然后使用客户端(和 StartExecutionRequest 对象)的标准构建器模式来触发您的执行:
SfnClient sfc = SfnClient.builder()
.region()
.build();
sfc.startExecution(startExecutionRequest);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.