Currently step functions graph are defined in json using ASL (Amazon States Language). There is no good way to to unit testing of the graphs being created and we have to rely on running the graph with mocked/some implementation of lambda functions on aws account. With launch of AWS CDK, is it possible to have the step function graphs also defined in high level language and do unit testing, mocking etc?
问问题
2094 次
1 回答
2
你试过@aws-cdk/aws-stepfunctions
图书馆吗?
从此处的文档中复制示例代码以供后代使用:
const submitLambda = new lambda.Function(this, 'SubmitLambda', { ... });
const getStatusLambda = new lambda.Function(this, 'CheckLambda', { ... });
const submitJob = new stepfunctions.Task(this, 'Submit Job', {
resource: submitLambda,
// Put Lambda's result here in the execution's state object
resultPath: '$.guid',
});
const waitX = new stepfunctions.Wait(this, 'Wait X Seconds', { secondsPath: '$.wait_time' });
const getStatus = new stepfunctions.Task(this, 'Get Job Status', {
resource: getStatusLambda,
// Pass just the field named "guid" into the Lambda, put the
// Lambda's result in a field called "status"
inputPath: '$.guid',
resultPath: '$.status',
});
const jobFailed = new stepfunctions.Fail(this, 'Job Failed', {
cause: 'AWS Batch Job Failed',
error: 'DescribeJob returned FAILED',
});
const finalStatus = new stepfunctions.Task(this, 'Get Final Job Status', {
resource: getStatusLambda,
// Use "guid" field as input, output of the Lambda becomes the
// entire state machine output.
inputPath: '$.guid',
});
const definition = submitJob
.next(waitX)
.next(getStatus)
.next(new stepfunctions.Choice(this, 'Job Complete?')
// Look at the "status" field
.when(stepfunctions.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
.when(stepfunctions.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
.otherwise(waitX));
new stepfunctions.StateMachine(this, 'StateMachine', {
definition,
timeoutSec: 300
});
于 2018-12-04T07:49:54.190 回答