- Create a Stepfunction
- Integrate Lambda Functions with a StepFunction
Create a Step function [Call a StepFunction] (https://aws.amazon.com/blogs/developer/stepfunctions-fluent-api/)
mvn compile package -Dmaven.test.skip=true
java -jar target/module-06-0.1.0.jar
- bucket=your bucket name
- prefix= your file prefix (for exmple, images/a.jpg)
curl 'localhost:8080/workshop/trans/integrated?bucket=<your_bucket>&prefix=<prefix>®ion=<region>'
- You definitely got error above 2.1 and 2.2, it is because you don't have Lambda functions
- You need to create this following step 2
- Change a resource value
{
"Comment" : "Machine learning execution with spot instance",
"StartAt" : "RetrieveInfoFromPhotoUsingRekognition",
"States" : {
"RetrieveInfoFromPhotoUsingRekognition": {
"Type" : "Task",
"Resource" : "arn:aws:lambda:us-east-1:550622896891:function:MyFunction-workshop-rekognition",
"Retry" : [ {"ErrorEquals":["HandledError"], "MaxAttempts":3} ],
"Next" : "TransInfoUsingTranlate"
},
"TransInfoUsingTranlate": {
"Type" : "Task",
"Resource" : "arn:aws:lambda:us-east-1:550622896891:function:MyFunction-workshop-translate",
"Next" : "StoreTransDataIntoDynamoDB"
},
"StoreTransDataIntoDynamoDB": {
"Type" : "Task",
"Resource" : "arn:aws:lambda:us-east-1:550622896891:function:MyFunction-workshop-dynamodb",
"Retry" : [ {"ErrorEquals":["HandledError"], "MaxAttempts":3} ],
"End": true
}
}
}
- change a bucket, prefix, sourceLangCode, targetLangCode
{
"bucket":"seon-virginia-2016",
"prefix":"images/a.jpeg",
"text" : "Hello, hello",
"translated" : "",
"sourceLangCode" :"en",
"targetLangCode" : "es"
}
Create a common Model class (StepEventInput, StepEventOutout)
StepEventInput.java (omit getter/setter)
private String id;
private String bucket;
private String prefix;
private String text;
private String translated;
private String sourceLangCode;
private String targetLangCode;
StepEventOutput.java (omit getter/setter)
private String text;
private String error_message;
{
"Comment" : "Machine learning execution with spot instance",
"StartAt" : "RetrieveInfoFromPhotoUsingRekognition",
"States" : {
"RetrieveInfoFromPhotoUsingRekognition": {
"Type" : "Task",
"Resource" : "arn:aws:lambda:us-east-1:550622896891:function:MyFunction-workshop-rekognition",
"Retry" : [ {"ErrorEquals":["HandledError"], "MaxAttempts":3} ],
"Next" : "TransInfoUsingTranlate"
},
"TransInfoUsingTranlate": {
"Type" : "Task",
"Resource" : "arn:aws:lambda:us-east-1:550622896891:function:MyFunction-workshop-translate",
"Next" : "StoreTransDataIntoDynamoDB"
},
"StoreTransDataIntoDynamoDB": {
"Type" : "Task",
"Resource" : "arn:aws:lambda:us-east-1:550622896891:function:MyFunction-workshop-dynamodb",
"Retry" : [ {"ErrorEquals":["HandledError"], "MaxAttempts":3} ],
"End": true
}
}
}
{
"bucket":"seon-virginia-2016",
"prefix":"images/a.jpeg",
"text" : "Hello, hello",
"translated" : "",
"sourceLangCode" :"en",
"targetLangCode" : "es"
}
final AWSStepFunctions stepFunctionclient = AWSStepFunctionsClientBuilder.defaultClient();
URL inputFile = Application.class.getResource("/aws/step-input.json");
String input = jsonFileRead(inputFile);
StartExecutionRequest startExecutionRequest
= new StartExecutionRequest()
.withInput(input)
.withStateMachineArn("arn:aws:states:us-east-1:5591:stateMachine:workshop-stepfunction").withSdkRequestTimeout(30000);
StartExecutionResult executionResult = stepFunctionclient.startExecution(startExecutionRequest);
Test a code and check the result.

