class StateMachine (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.StepFunctions.StateMachine |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#StateMachine |
![]() | software.amazon.awscdk.services.stepfunctions.StateMachine |
![]() | aws_cdk.aws_stepfunctions.StateMachine |
![]() | aws-cdk-lib » aws_stepfunctions » StateMachine |
Implements
IConstruct
, IDependable
, IResource
, IState
, IGrantable
Define a StepFunctions State Machine.
Example
// Define a state machine with one Pass state
const child = new sfn.StateMachine(this, 'ChildStateMachine', {
definition: sfn.Chain.start(new sfn.Pass(this, 'PassState')),
});
// Include the state machine in a Task state with callback pattern
const task = new tasks.StepFunctionsStartExecution(this, 'ChildTask', {
stateMachine: child,
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
input: sfn.TaskInput.fromObject({
token: sfn.JsonPath.taskToken,
foo: 'bar',
}),
name: 'MyExecutionName',
});
// Define a second state machine with the Task state above
new sfn.StateMachine(this, 'ParentStateMachine', {
definition: task,
});
Initializer
new StateMachine(scope: Construct, id: string, props: StateMachineProps)
Parameters
- scope
Construct
- id
string
- props
State
Machine Props
Construct Props
Name | Type | Description |
---|---|---|
comment? | string | Comment that describes this state machine. |
definition? | IChainable | Definition for this state machine. |
definition | Definition | Definition for this state machine. |
definition | { [string]: string } | substitutions for the definition body as a key-value map. |
encryption | Encryption | Configures server-side encryption of the state machine definition and execution history. |
logs? | Log | Defines what execution history events are logged and where they are logged. |
query | Query | The name of the query language used by the state machine. |
removal | Removal | The removal policy to apply to state machine. |
role? | IRole | The execution role for the state machine service. |
state | string | A name for the state machine. |
state | State | Type of the state machine. |
timeout? | Duration | Maximum run time for this state machine. |
tracing | boolean | Specifies whether Amazon X-Ray tracing is enabled for this state machine. |
comment?
Type:
string
(optional, default: No comment)
Comment that describes this state machine.
definition?
⚠️ Deprecated: use definitionBody: DefinitionBody.fromChainable()
Type:
IChainable
(optional)
Definition for this state machine.
definitionBody?
Type:
Definition
(optional)
Definition for this state machine.
definitionSubstitutions?
Type:
{ [string]: string }
(optional)
substitutions for the definition body as a key-value map.
encryptionConfiguration?
Type:
Encryption
(optional, default: data is transparently encrypted using an AWS owned key)
Configures server-side encryption of the state machine definition and execution history.
logs?
Type:
Log
(optional, default: No logging)
Defines what execution history events are logged and where they are logged.
queryLanguage?
Type:
Query
(optional, default: 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.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.DESTROY)
The removal policy to apply to state machine.
role?
Type:
IRole
(optional, default: A role is automatically created)
The execution role for the state machine service.
stateMachineName?
Type:
string
(optional, default: A name is automatically generated)
A name for the state machine.
stateMachineType?
Type:
State
(optional, default: StateMachineType.STANDARD)
Type of the state machine.
timeout?
Type:
Duration
(optional, default: No timeout)
Maximum run time for this state machine.
tracingEnabled?
Type:
boolean
(optional, default: false)
Specifies whether Amazon X-Ray tracing is enabled for this state machine.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
grant | IPrincipal | The principal this state machine is running as. |
node | Node | The tree node. |
role | IRole | Execution role of this state machine. |
stack | Stack | The stack in which this resource is defined. |
state | string | The ARN of the state machine. |
state | string | The name of the state machine. |
state | string | Identifier for the state machine revision, which is an immutable, read-only snapshot of a state machine’s definition and configuration. |
state | State | Type of the state machine. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
grantPrincipal
Type:
IPrincipal
The principal this state machine is running as.
node
Type:
Node
The tree node.
role
Type:
IRole
Execution role of this state machine.
stack
Type:
Stack
The stack in which this resource is defined.
stateMachineArn
Type:
string
The ARN of the state machine.
stateMachineName
Type:
string
The name of the state machine.
stateMachineRevisionId
Type:
string
Identifier for the state machine revision, which is an immutable, read-only snapshot of a state machine’s definition and configuration.
stateMachineType
Type:
State
Type of the state machine.
Methods
Name | Description |
---|---|
add | Add the given statement to the role's policy. |
apply | Apply the given removal policy to this resource. |
grant(identity, ...actions) | Grant the given identity custom permissions. |
grant | Grant the given identity permissions on all executions of the state machine. |
grant | Grant the given identity permissions to read results from state machine. |
grant | Grant the given identity permissions to start an execution of this state machine. |
grant | Grant the given identity permissions to start a synchronous execution of this state machine. |
grant | Grant the given identity task response permissions on a state machine. |
metric(metricName, props?) | Return the given named metric for this State Machine's executions. |
metric | Metric for the number of executions that were aborted. |
metric | Metric for the number of executions that failed. |
metric | Metric for the number of executions that were started. |
metric | Metric for the number of executions that succeeded. |
metric | Metric for the number of executions that were throttled. |
metric | Metric for the interval, in milliseconds, between the time the execution starts and the time it closes. |
metric | Metric for the number of executions that timed out. |
to | Returns a string representation of this construct. |
static from | Import a state machine. |
static from | Import a state machine via resource name. |
addToRolePolicy(statement)
public addToRolePolicy(statement: PolicyStatement): void
Parameters
- statement
Policy
Statement
Add the given statement to the role's policy.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
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
).
grant(identity, ...actions)
public grant(identity: IGrantable, ...actions: string[]): Grant
Parameters
- identity
IGrantable
- actions
string
Returns
Grant the given identity custom permissions.
grantExecution(identity, ...actions)
public grantExecution(identity: IGrantable, ...actions: string[]): Grant
Parameters
- identity
IGrantable
- actions
string
Returns
Grant the given identity permissions on all executions of the state machine.
grantRead(identity)
public grantRead(identity: IGrantable): Grant
Parameters
- identity
IGrantable
Returns
Grant the given identity permissions to read results from state machine.
grantStartExecution(identity)
public grantStartExecution(identity: IGrantable): Grant
Parameters
- identity
IGrantable
Returns
Grant the given identity permissions to start an execution of this state machine.
grantStartSyncExecution(identity)
public grantStartSyncExecution(identity: IGrantable): Grant
Parameters
- identity
IGrantable
Returns
Grant the given identity permissions to start a synchronous execution of this state machine.
grantTaskResponse(identity)
public grantTaskResponse(identity: IGrantable): Grant
Parameters
- identity
IGrantable
Returns
Grant the given identity task response permissions on a state machine.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this State Machine's executions.
metricAborted(props?)
public metricAborted(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of executions that were aborted.
metricFailed(props?)
public metricFailed(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of executions that failed.
metricStarted(props?)
public metricStarted(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of executions that were started.
metricSucceeded(props?)
public metricSucceeded(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of executions that succeeded.
metricThrottled(props?)
public metricThrottled(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of executions that were throttled.
metricTime(props?)
public metricTime(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the interval, in milliseconds, between the time the execution starts and the time it closes.
metricTimedOut(props?)
public metricTimedOut(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of executions that timed out.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromStateMachineArn(scope, id, stateMachineArn)
public static fromStateMachineArn(scope: Construct, id: string, stateMachineArn: string): IStateMachine
Parameters
- scope
Construct
- id
string
- stateMachineArn
string
Returns
Import a state machine.
static fromStateMachineName(scope, id, stateMachineName)
public static fromStateMachineName(scope: Construct, id: string, stateMachineName: string): IStateMachine
Parameters
- scope
Construct
- id
string
- stateMachineName
string
Returns
Import a state machine via resource name.