filmov
tv
AWs Step Function Task and Parallel State explanation

Показать описание
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();
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();
Комментарии