import * as cdk from 'aws-cdk-lib';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
import * as sns from 'aws-cdk-lib/aws-sns';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'my-stack');
const topic = new sns.Topic(stack, 'MyTopic');
const definition = new sfn.Pass(stack, 'Start State');
definition.next(new tasks.SnsPublish(stack, 'Publish to SNS', {
topic: topic,
message: sfn.TaskInput.fromJsonPathAt('$'),
}));
const stateMachine = new sfn.StateMachine(stack, 'MyStateMachine', {
definition,
});
...
definition.next(new tasks.SnsPublish(stack, 'Publish to SNS', {
topic: topic,
message: tasks.TaskInput.fromObject({
name: sfn.JsonPath.stringAt('$.name'),
message: 'Hello, !',
}),
}));
...
这个例子将消息设置为“Hello,
const execution = stateMachine.startExecution({
name: 'Bob',
});
在这个例子中,输入参数被设置为name:“Bob”。当状态机被启动时,它将从输入参数中获取Bob,并将其注入到SNS消息中,将消息设置为“Hello,Bob!”。