StepFunctionsStartExecution Class
Use an AWS Step function as a target for AWS EventBridge Scheduler.
Example
ts
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
const payload = {
Name: "MyParameter",
Value: '🌥️',
};
const putParameterStep = new tasks.CallAwsService(this, 'PutParameter', {
service: 'ssm',
action: 'putParameter',
iamResources: ['*'],
parameters: {
"Name.$": '$.Name',
"Value.$": '$.Value',
Type: 'String',
Overwrite: true,
},
});
const stateMachine = new sfn.StateMachine(this, 'StateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(putParameterStep)
});
new Schedule(this, 'Schedule', {
schedule: ScheduleExpression.rate(Duration.hours(1)),
target: new targets.StepFunctionsStartExecution(stateMachine, {
input: ScheduleTargetInput.fromObject(payload),
}),
});
python
import aws_cdk.aws_stepfunctions as sfn
import aws_cdk.aws_stepfunctions_tasks as tasks
payload = {
"Name": "MyParameter",
"Value": "🌥️"
}
put_parameter_step = tasks.CallAwsService(self, "PutParameter",
service="ssm",
action="putParameter",
iam_resources=["*"],
parameters={
"Name.$": "$.Name",
"Value.$": "$.Value",
"Type": "String",
"Overwrite": True
}
)
state_machine = sfn.StateMachine(self, "StateMachine",
definition_body=sfn.DefinitionBody.from_chainable(put_parameter_step)
)
Schedule(self, "Schedule",
schedule=ScheduleExpression.rate(Duration.hours(1)),
target=targets.StepFunctionsStartExecution(state_machine,
input=ScheduleTargetInput.from_object(payload)
)
)
java
import software.amazon.awscdk.services.stepfunctions.*;
import software.amazon.awscdk.services.stepfunctions.tasks.*;
Map<String, String> payload = Map.of(
"Name", "MyParameter",
"Value", "🌥️");
CallAwsService putParameterStep = CallAwsService.Builder.create(this, "PutParameter")
.service("ssm")
.action("putParameter")
.iamResources(List.of("*"))
.parameters(Map.of(
"Name.$", "$.Name",
"Value.$", "$.Value",
"Type", "String",
"Overwrite", true))
.build();
StateMachine stateMachine = StateMachine.Builder.create(this, "StateMachine")
.definitionBody(DefinitionBody.fromChainable(putParameterStep))
.build();
Schedule.Builder.create(this, "Schedule")
.schedule(ScheduleExpression.rate(Duration.hours(1)))
.target(StepFunctionsStartExecution.Builder.create(stateMachine)
.input(ScheduleTargetInput.fromObject(payload))
.build())
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.StepFunctions;
using Amazon.CDK.AWS.StepFunctions.Tasks;
IDictionary<string, string> payload = new Dictionary<string, string> {
{ "Name", "MyParameter" },
{ "Value", "🌥️" }
};
var putParameterStep = new CallAwsService(this, "PutParameter", new CallAwsServiceProps {
Service = "ssm",
Action = "putParameter",
IamResources = new [] { "*" },
Parameters = new Dictionary<string, object> {
{ "Name.$", "$.Name" },
{ "Value.$", "$.Value" },
{ "Type", "String" },
{ "Overwrite", true }
}
});
var stateMachine = new StateMachine(this, "StateMachine", new StateMachineProps {
DefinitionBody = DefinitionBody.FromChainable(putParameterStep)
});
new Schedule(this, "Schedule", new ScheduleProps {
Schedule = ScheduleExpression.Rate(Duration.Hours(1)),
Target = new StepFunctionsStartExecution(stateMachine, new ScheduleTargetBaseProps {
Input = ScheduleTargetInput.FromObject(payload)
})
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import tasks "github.com/aws/aws-cdk-go/awscdk"
payload := map[string]*string{
"Name": jsii.String("MyParameter"),
"Value": jsii.String("🌥️"),
}
putParameterStep := tasks.NewCallAwsService(this, jsii.String("PutParameter"), &CallAwsServiceProps{
Service: jsii.String("ssm"),
Action: jsii.String("putParameter"),
IamResources: []*string{
jsii.String("*"),
},
Parameters: map[string]interface{}{
"Name.$": jsii.String("$.Name"),
"Value.$": jsii.String("$.Value"),
"Type": jsii.String("String"),
"Overwrite": jsii.Boolean(true),
},
})
stateMachine := sfn.NewStateMachine(this, jsii.String("StateMachine"), &StateMachineProps{
DefinitionBody: sfn.DefinitionBody_FromChainable(putParameterStep),
})
awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Hours(jsii.Number(1))),
Target: targets.NewStepFunctionsStartExecution(stateMachine, &ScheduleTargetBaseProps{
Input: awscdk.ScheduleTargetInput_FromObject(payload),
}),
})
Initializer
ts
new StepFunctionsStartExecution(stateMachine: IStateMachine, props: ScheduleTargetBaseProps)
python
StepFunctionsStartExecution(state_machine: IStateMachine, props: ScheduleTargetBaseProps)
java
new StepFunctionsStartExecution(IStateMachine stateMachine, ScheduleTargetBaseProps props)
csharp
new StepFunctionsStartExecution(IStateMachine stateMachine, ScheduleTargetBaseProps props)
go
NewStepFunctionsStartExecution(StateMachine IStateMachine, Props ScheduleTargetBaseProps)
Methods
bind(schedule: ISchedule): ScheduleTargetConfigdef bind(self, schedule: ISchedule) -> ScheduleTargetConfigpublic ScheduleTargetConfig bind(ISchedule schedule)public ScheduleTargetConfig Bind(ISchedule schedule)func Bind(Schedule ISchedule) ScheduleTargetConfig#Create a return a Schedule Target Configuration for the given schedule.
returns
Returns: a Schedule Target Configuration