Skip to content
v2.273.0

StateMachine L2 construct ​

Define a StepFunctions State Machine.

Example ​

ts
import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions';

const pipeline = new codepipeline.Pipeline(this, 'MyPipeline');
const inputArtifact = new codepipeline.Artifact();
const startState = new stepfunctions.Pass(this, 'StartState');
const simpleStateMachine  = new stepfunctions.StateMachine(this, 'SimpleStateMachine', {
  definition: startState,
});
const stepFunctionAction = new codepipeline_actions.StepFunctionInvokeAction({
  actionName: 'Invoke',
  stateMachine: simpleStateMachine,
  stateMachineInput: codepipeline_actions.StateMachineInput.filePath(inputArtifact.atPath('assets/input.json')),
});
pipeline.addStage({
  stageName: 'StepFunctions',
  actions: [stepFunctionAction],
});
python
import aws_cdk.aws_stepfunctions as stepfunctions


pipeline = codepipeline.Pipeline(self, "MyPipeline")
input_artifact = codepipeline.Artifact()
start_state = stepfunctions.Pass(self, "StartState")
simple_state_machine = stepfunctions.StateMachine(self, "SimpleStateMachine",
    definition=start_state
)
step_function_action = codepipeline_actions.StepFunctionInvokeAction(
    action_name="Invoke",
    state_machine=simple_state_machine,
    state_machine_input=codepipeline_actions.StateMachineInput.file_path(input_artifact.at_path("assets/input.json"))
)
pipeline.add_stage(
    stage_name="StepFunctions",
    actions=[step_function_action]
)
java
import software.amazon.awscdk.services.stepfunctions.*;


Pipeline pipeline = new Pipeline(this, "MyPipeline");
Artifact inputArtifact = new Artifact();
Pass startState = new Pass(this, "StartState");
StateMachine simpleStateMachine = StateMachine.Builder.create(this, "SimpleStateMachine")
        .definition(startState)
        .build();
StepFunctionInvokeAction stepFunctionAction = StepFunctionInvokeAction.Builder.create()
        .actionName("Invoke")
        .stateMachine(simpleStateMachine)
        .stateMachineInput(StateMachineInput.filePath(inputArtifact.atPath("assets/input.json")))
        .build();
pipeline.addStage(StageOptions.builder()
        .stageName("StepFunctions")
        .actions(List.of(stepFunctionAction))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.StepFunctions;


var pipeline = new Pipeline(this, "MyPipeline");
var inputArtifact = new Artifact();
var startState = new Pass(this, "StartState");
var simpleStateMachine = new StateMachine(this, "SimpleStateMachine", new StateMachineProps {
    Definition = startState
});
var stepFunctionAction = new StepFunctionInvokeAction(new StepFunctionsInvokeActionProps {
    ActionName = "Invoke",
    StateMachine = simpleStateMachine,
    StateMachineInput = StateMachineInput.FilePath(inputArtifact.AtPath("assets/input.json"))
});
pipeline.AddStage(new StageOptions {
    StageName = "StepFunctions",
    Actions = new [] { stepFunctionAction }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"


pipeline := codepipeline.NewPipeline(this, jsii.String("MyPipeline"))
inputArtifact := codepipeline.NewArtifact()
startState := stepfunctions.NewPass(this, jsii.String("StartState"))
simpleStateMachine := stepfunctions.NewStateMachine(this, jsii.String("SimpleStateMachine"), &StateMachineProps{
	Definition: startState,
})
stepFunctionAction := codepipeline_actions.NewStepFunctionInvokeAction(&StepFunctionsInvokeActionProps{
	ActionName: jsii.String("Invoke"),
	StateMachine: simpleStateMachine,
	StateMachineInput: codepipeline_actions.StateMachineInput_FilePath(inputArtifact.AtPath(jsii.String("assets/input.json"))),
})
pipeline.AddStage(&StageOptions{
	StageName: jsii.String("StepFunctions"),
	Actions: []IAction{
		stepFunctionAction,
	},
})

Initializer ​

ts
new StateMachine(scope: Construct, id: string, props: StateMachineProps)
python
StateMachine(scope: Construct, id: str, props: StateMachineProps)
java
new StateMachine(Construct scope, String id, StateMachineProps props)
csharp
new StateMachine(Construct scope, string id, StateMachineProps props)
go
NewStateMachine(Scope Construct, Id *string, Props StateMachineProps)

Construct Props ​

commentstringcommentstrcommentStringCommentstringComment*string= No comment#
Comment that describes this state machine.
definitionIChainabledefinitionIChainabledefinitionIChainableDefinitionIChainableDefinitionIChainabledeprecated#
use definitionBody: DefinitionBody.fromChainable()
definitionBodyDefinitionBodydefinition_bodyDefinitionBodydefinitionBodyDefinitionBodyDefinitionBodyDefinitionBodyDefinitionBodyDefinitionBody#
Definition for this state machine.
definitionSubstitutions{ [key: string]: string }definition_substitutionstyping.Mapping[str, str]definitionSubstitutionsMap<String, String>DefinitionSubstitutionsIDictionary<string, string>DefinitionSubstitutions*map[string]*string#
substitutions for the definition body as a key-value map.
encryptionConfigurationEncryptionConfigurationencryption_configurationEncryptionConfigurationencryptionConfigurationEncryptionConfigurationEncryptionConfigurationEncryptionConfigurationEncryptionConfigurationEncryptionConfiguration= data is transparently encrypted …#
Configures server-side encryption of the state machine definition and execution history.
default

Default: data is transparently encrypted using an AWS owned key

Defines what execution history events are logged and where they are logged.
queryLanguageQueryLanguagequery_languageQueryLanguagequeryLanguageQueryLanguageQueryLanguageQueryLanguageQueryLanguageQueryLanguage= JSON_PATH#
The name of the query language used by the state machine.

If the state does not contain a queryLanguage field, then it will use the query language specified in this queryLanguage field.

removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= RemovalPolicy.DESTROY#
The removal policy to apply to state machine.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRole= A role is automatically created#
The execution role for the state machine service.
stateMachineNamestringstate_machine_namestrstateMachineNameStringStateMachineNamestringStateMachineName*string= A name is automatically generate…#
A name for the state machine.
default

Default: A name is automatically generated

stateMachineTypeStateMachineTypestate_machine_typeStateMachineTypestateMachineTypeStateMachineTypeStateMachineTypeStateMachineTypeStateMachineTypeStateMachineType= StateMachineType.STANDARD#
Type of the state machine.
timeoutDurationtimeoutDurationtimeoutDurationTimeoutDurationTimeoutDuration= No timeout#
Maximum run time for this state machine.
tracingEnabledbooleantracing_enabledbooltracingEnabledBooleanTracingEnabledboolTracingEnabled*bool= false#
Specifies whether Amazon X-Ray tracing is enabled for this state machine.

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#
The principal this state machine is running as.
Collection of grant methods for a StateMachine.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRolerequired#
Execution role of this state machine.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
stateMachineArnstringstate_machine_arnstrstateMachineArnStringStateMachineArnstringStateMachineArn*stringrequired#
The ARN of the state machine.
stateMachineNamestringstate_machine_namestrstateMachineNameStringStateMachineNamestringStateMachineName*stringrequired#
The name of the state machine.
stateMachineRefStateMachineReferencestate_machine_refStateMachineReferencestateMachineRefStateMachineReferenceStateMachineRefStateMachineReferenceStateMachineRefStateMachineReferencerequired#
A reference to a StateMachine resource.
stateMachineRevisionIdstringstate_machine_revision_idstrstateMachineRevisionIdStringStateMachineRevisionIdstringStateMachineRevisionId*stringrequired#
Identifier for the state machine revision, which is an immutable, read-only snapshot of a state machine’s definition and configuration.
stateMachineTypeStateMachineTypestate_machine_typeStateMachineTypestateMachineTypeStateMachineTypeStateMachineTypeStateMachineTypeStateMachineTypeStateMachineTyperequired#
Type of the state machine.

Methods ​

addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#
Add the given statement to the role's policy.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromStateMachineArn(scope: Construct, id: string, stateMachineArn: string): IStateMachine@staticmethod def from_state_machine_arn(scope: Construct, id: str, state_machine_arn: str) -> IStateMachinepublic static IStateMachine fromStateMachineArn(Construct scope, String id, String stateMachineArn)public static IStateMachine FromStateMachineArn(Construct scope, string id, string stateMachineArn)func FromStateMachineArn(Scope Construct, Id *string, StateMachineArn *string) IStateMachinestatic#
Import a state machine.
fromStateMachineName(scope: Construct, id: string, stateMachineName: string): IStateMachine@staticmethod def from_state_machine_name(scope: Construct, id: str, state_machine_name: str) -> IStateMachinepublic static IStateMachine fromStateMachineName(Construct scope, String id, String stateMachineName)public static IStateMachine FromStateMachineName(Construct scope, string id, string stateMachineName)func FromStateMachineName(Scope Construct, Id *string, StateMachineName *string) IStateMachinestatic#
Import a state machine via resource name.
grant(identity: IGrantable, ...actions: string[]): Grantdef grant(self, identity: IGrantable, actions: str) -> Grantpublic Grant grant(IGrantable identity, String actions)public Grant Grant(IGrantable identity, string actions)func Grant(Identity IGrantable, Actions *string) Grant#
Grant the given identity custom permissions.

[disable-awslint:no-grants]

grantExecution(identity: IGrantable, ...actions: string[]): Grantdef grant_execution(self, identity: IGrantable, actions: str) -> Grantpublic Grant grantExecution(IGrantable identity, String actions)public Grant GrantExecution(IGrantable identity, string actions)func GrantExecution(Identity IGrantable, Actions *string) Grant#
Grant the given identity permissions on all executions of the state machine.

The use of this method is discouraged. Please use grants.execution() instead.

[disable-awslint:no-grants]

grantRead(identity: IGrantable): Grantdef grant_read(self, identity: IGrantable) -> Grantpublic Grant grantRead(IGrantable identity)public Grant GrantRead(IGrantable identity)func GrantRead(Identity IGrantable) Grant#
Grant the given identity permissions to read results from state machine.

The use of this method is discouraged. Please use grants.read() instead.

[disable-awslint:no-grants]

grantRedriveExecution(identity: IGrantable): Grantdef grant_redrive_execution(self, identity: IGrantable) -> Grantpublic Grant grantRedriveExecution(IGrantable identity)public Grant GrantRedriveExecution(IGrantable identity)func GrantRedriveExecution(Identity IGrantable) Grant#
Grant the given identity permission to redrive the execution of the state machine.

The use of this method is discouraged. Please use grants.redriveExecution() instead.

[disable-awslint:no-grants]

grantStartExecution(identity: IGrantable): Grantdef grant_start_execution(self, identity: IGrantable) -> Grantpublic Grant grantStartExecution(IGrantable identity)public Grant GrantStartExecution(IGrantable identity)func GrantStartExecution(Identity IGrantable) Grant#
Grant the given identity permissions to start an execution of this state machine.

The use of this method is discouraged. Please use grants.startExecution() instead.

[disable-awslint:no-grants]

grantStartSyncExecution(identity: IGrantable): Grantdef grant_start_sync_execution(self, identity: IGrantable) -> Grantpublic Grant grantStartSyncExecution(IGrantable identity)public Grant GrantStartSyncExecution(IGrantable identity)func GrantStartSyncExecution(Identity IGrantable) Grant#
Grant the given identity permissions to start a synchronous execution of this state machine.

The use of this method is discouraged. Please use grants.startSyncExecution() instead.

[disable-awslint:no-grants]

grantTaskResponse(identity: IGrantable): Grantdef grant_task_response(self, identity: IGrantable) -> Grantpublic Grant grantTaskResponse(IGrantable identity)public Grant GrantTaskResponse(IGrantable identity)func GrantTaskResponse(Identity IGrantable) Grant#
Grant the given identity task response permissions on a state machine.

The use of this method is discouraged. Please use grants.taskResponse() instead.

[disable-awslint:no-grants]

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
metric(metricName: string, props?: MetricOptions): Metricdef metric(self, metric_name: str, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricOptions props)public Metric Metric(string metricName, MetricOptions? props = null)func Metric(MetricName *string, Props MetricOptions) Metric#
Return the given named metric for this State Machine's executions.
metricAborted(props?: MetricOptions): Metricdef metric_aborted(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricAborted(MetricOptions props)public Metric MetricAborted(MetricOptions? props = null)func MetricAborted(Props MetricOptions) Metric#
Metric for the number of executions that were aborted.
metricFailed(props?: MetricOptions): Metricdef metric_failed(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricFailed(MetricOptions props)public Metric MetricFailed(MetricOptions? props = null)func MetricFailed(Props MetricOptions) Metric#
Metric for the number of executions that failed.
metricStarted(props?: MetricOptions): Metricdef metric_started(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricStarted(MetricOptions props)public Metric MetricStarted(MetricOptions? props = null)func MetricStarted(Props MetricOptions) Metric#
Metric for the number of executions that were started.
metricSucceeded(props?: MetricOptions): Metricdef metric_succeeded(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricSucceeded(MetricOptions props)public Metric MetricSucceeded(MetricOptions? props = null)func MetricSucceeded(Props MetricOptions) Metric#
Metric for the number of executions that succeeded.
metricThrottled(props?: MetricOptions): Metricdef metric_throttled(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricThrottled(MetricOptions props)public Metric MetricThrottled(MetricOptions? props = null)func MetricThrottled(Props MetricOptions) Metric#
Metric for the number of executions that were throttled.
metricTime(props?: MetricOptions): Metricdef metric_time(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricTime(MetricOptions props)public Metric MetricTime(MetricOptions? props = null)func MetricTime(Props MetricOptions) Metric#
Metric for the interval, in milliseconds, between the time the execution starts and the time it closes.
metricTimedOut(props?: MetricOptions): Metricdef metric_timed_out(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricTimedOut(MetricOptions props)public Metric MetricTimedOut(MetricOptions? props = null)func MetricTimedOut(Props MetricOptions) Metric#
Metric for the number of executions that timed out.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.