AWS CloudFormation
User Guide (Version )

AWS::StepFunctions::StateMachine

Provisions a state machine. A state machine consists of a collection of states that can do work (Task states), determine to which states to transition next (Choice states), stop an execution with an error (Fail states), and so on. State machines are specified using a JSON-based, structured language.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::StepFunctions::StateMachine", "Properties" : { "DefinitionString" : String, "RoleArn" : String, "StateMachineName" : String, "Tags" : [ TagsEntry, ... ] } }

YAML

Type: AWS::StepFunctions::StateMachine Properties: DefinitionString: String RoleArn: String StateMachineName: String Tags: - TagsEntry

Properties

DefinitionString

The Amazon States Language definition of the state machine. See Amazon States Language.

Required: Yes

Type: String

Update requires: No interruption

RoleArn

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

Required: Yes

Type: String

Update requires: No interruption

StateMachineName

The name of the state machine.

A name must not contain:

  • white space

  • brackets < > { } [ ]

  • wildcard characters ? *

  • special characters " # % \ ^ | ~ ` $ & , ; : /

  • control characters (U+0000-001F, U+007F-009F)

Required: No

Type: String

Update requires: Replacement

Tags

The list of tags to add to a resource.

Tags may only contain Unicode letters, digits, white space, or these symbols: _ . : / = + - @.

Required: No

Type: List of TagsEntry

Update requires: No interruption

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:

{ "Ref": "MyStateMachine" }Guide

Returns a value similar to the following:

arn:aws:states:us-east-1:111122223333:stateMachine:HelloWorld-StateMachine

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:

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

Returns the name of your state machine:

HelloWorld-StateMachine

If you did not specify the name it will be similar to the following:

MyStateMachine-1234abcdefgh

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

Examples

The following examples create a Step Functions state machine.

Using a Single-Line Property

JSON

{ "AWSTemplateFormatVersion":"2010-09-09", "Description":"An example template for a Step Functions state machine.", "Resources":{ "MyStateMachine":{ "Type":"AWS::StepFunctions::StateMachine", "Properties":{ "StateMachineName":"HelloWorld-StateMachine", "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

JSON

{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "An example template for a Step Functions state machine.", "Resources": { "MyStateMachine": { "Type": "AWS::StepFunctions::StateMachine", "Properties": { "StateMachineName" : "HelloWorld-StateMachine", "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", "Tags": [ { "Key": "keyname1", "Value": "value1" }, { "Key": "keyname2", "Value": "value2" } ] } } } }

Including Tags

YAML

AWSTemplateFormatVersion: '2010-09-09' Description: An example template for a Step Functions state machine. Resources: MyStateMachine: Type: AWS::StepFunctions::StateMachine Properties: StateMachineName: HelloWorld-StateMachine 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 Tags: - Key: "keyname1" Value: "value1" - Key: "keyname2" Value: "value2"