AWs Step Function Task and Parallel State explanation

preview_player
Показать описание
Here I have explained how AWS Step function works and some of its use cases. Also Explained how Task and parallel State works and input between states.

Code for Parallel -
{
"Comment": "A description of my state machine",
"StartAt": "Parallel",
"States": {
"Parallel": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Lambda 1",
"States": {
"Lambda 1": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
"FunctionName": "Lambda ARN"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"End": true
}
}
},
{
"StartAt": "Lambda 2",
"States": {
"Lambda 2": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
"FunctionName": "Lambda ARN"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"End": true
}
}
}
],
"Next": "Lambda 3"
},
"Lambda 3": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
"FunctionName": "Lambda ARN"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"End": true
}
}
}
----------------------------------------------------------------

Code for Sequential -
{
"Comment": "A Test step function with 2 lambda call ",
"StartAt": "Lambda1",
"States": {
"Lambda1": {
"Type": "Task",
"InputPath": "$",
"ResultPath": "$.taskresult",
"Resource": "Lambda ARN",
"Next": "Lambda2"
},
"Lambda2": {
"Type": "Task",
"InputPath": "$",
"ResultPath": "$.taskresult",
"Resource": "Lambda ARN",
"End": true,
"TimeoutSeconds": 20
}
}
}

-----------------------------------------------------------------------------------------

String accessKey = ""
String secretKey = ""
String EmailServiceStepFunctionARN = "arn:aws:states:us-east-2:417434344042:stateMachine:TestStateMachine"
UUID uuid = UUID.randomUUID();
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
StartExecutionRequest executionRequest = new StartExecutionRequest();

Map input = [:]
ObjectMapper mapper = new ObjectMapper();

Рекомендации по теме
Комментарии
Автор

Hi Ashish,

Can you please tell how to check the parallel step status and make step function as fail if anyone of the lambda has failed.

For example I have 3 glue jobs running parallel in the parallel step and one of the job was failed. Based on the status I need to mark the entire step function as failed.

finance_freedum
visit shbcf.ru