Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::StepFunctions::StateMachine

Use the AWS::StepFunctions::StateMachine resource to create an AWS Step Functions state machine.

Note

AWS CloudFormation automatically generates a name for your state machine. If you change the contents of the DefinitionString or RoleArn properties and update the stack, AWS CloudFormation generates a new state machine name and deletes the old state machine.

For information about creating state machines, see Tutorial: A Lambda State Machine in the AWS Step Functions Developer Guide and CreateStateMachine in the AWS Step Functions API Reference.

Syntax

JSON

Copy
{ "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": String, "RoleArn": String } }

YAML

Copy
Type: "AWS::StepFunctions::StateMachine" Properties: DefinitionString: String RoleArn: String

Properties

DefinitionString

The Amazon States Language definition of the state machine. For more information, see Amazon States Language in the AWS Step Functions Developer Guide.

Required: Yes

Type: String

Update requires: Replacement

RoleArn

The Amazon Resource Name (ARN) of the IAM role to use for this state machine.

Required: Yes

Type: String

Update requires: Replacement

Return Values

Ref

When you provide the logical ID of this resource to the Ref intrinsic function, Ref returns the ARN of the created state machine. For example:

Copy
{ "Ref": "MyStateMachine" }

Returns a value similar to the following:

Copy
arn:aws:states:us-east-1:111122223333:stateMachine:MyStateMachine-ABCDEFGHIJ1K

For more information about using the Ref function, see Ref.

Fn::GetAtt

Fn::GetAtt returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

Name

Returns the name of the state machine. For example:

Copy
{ "Fn::GetAtt": ["MyStateMachine", "Name"] }

Returns a value similar to the following:

Copy
MyStateMachine-ABCDEFGHIJ1K

For more information about using Fn::GetAtt, see Fn::GetAtt.

Examples

The following examples create a Step Functions state machine.

JSON

Using a Single-Line Property

Copy
{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "An example template for a Step Functions state machine.", "Resources" : { "MyStateMachine" : { "Type" : "AWS::StepFunctions::StateMachine", "Properties" : { "DefinitionString" : "{\"StartAt\": \"HelloWorld\", \"States\": {\"HelloWorld\": {\"Type\": \"Task\", \"Resource\": \"arn:aws:lambda:us-east-1:111122223333:function:HelloFunction\", \"End\": true}}}", "RoleArn" : "arn:aws:iam::111122223333:role/service-role/StatesExecutionRole-us-east-1" } } } }

Using the Fn::Join Intrinsic Function

Copy
{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "An example template for a Step Functions state machine.", "Resources": { "MyStateMachine": { "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", " \"StartAt\": \"HelloWorld\",", " \"States\" : {", " \"HelloWorld\" : {", " \"Type\" : \"Task\", ", " \"Resource\" : \"arn:aws:lambda:us-east-1:111122223333:function:HelloFunction\",", " \"End\" : true", " }", " }", "}" ] ] }, "RoleArn" : "arn:aws:iam::111122223333:role/service-role/StatesExecutionRole-us-east-1" } } } }

YAML

Copy
AWSTemplateFormatVersion: '2010-09-09' Description: An example template for a Step Functions state machine. Resources: MyStateMachine: Type: AWS::StepFunctions::StateMachine Properties: DefinitionString: |- { "StartAt": "HelloWorld", "States": { "HelloWorld": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:111122223333:function:HelloFunction", "End": true } } } RoleArn: arn:aws:iam::111122223333:role/service-role/StatesExecutionRole-us-east-1