AWS::Serverless::StateMachine
Creates an AWS Step Functions state machine, which you can use to orchestrate AWS Lambda functions and other AWS resources to form complex and robust workflows.
For more information about Step Functions, see the AWS Step Functions Developer Guide.
Note
When you deploy to AWS CloudFormation, AWS SAM transforms your AWS SAM resources into AWS CloudFormation resources. For more information, see Generated AWS CloudFormation resources for AWS SAM.
Syntax
To declare this entity in your AWS Serverless Application Model (AWS SAM) template, use the following syntax.
YAML
Type: AWS::Serverless::StateMachine Properties: AutoPublishAlias:StringUseAliasAsEventTarget:BooleanDefinition:MapDefinitionSubstitutions:MapDefinitionUri:String | S3LocationDeploymentPreference:DeploymentPreferenceEvents:EventSourceLogging:LoggingConfigurationName:StringPermissionsBoundary:StringPolicies:String | List | MapPropagateTags:BooleanRolePath:StringRole:StringTags:MapTracing:TracingConfigurationType:String
Properties
- 
					AutoPublishAlias
- 
					The name of the state machine alias. To learn more about using Step Functions state machine aliases, see Manage continuous deployments with versions and aliases in the AWS Step Functions Developer Guide. Use DeploymentPreferenceto configure deployment preferences for your alias. If you don’t specifyDeploymentPreference, AWS SAM will configure traffic to shift to the newer state machine version all at once.AWS SAM sets the version’s DeletionPolicyandUpdateReplacePolicytoRetainby default. Previous versions will not be deleted automatically.Type: String Required: No AWS CloudFormation compatibility: This property is passed directly to the Nameproperty of anAWS::StepFunctions::StateMachineAliasresource.
- 
					UseAliasAsEventTarget
- 
					Indicate whether or not to pass the alias, created by using the AutoPublishAliasproperty, to the events source's target defined with Events.Specify Trueto use the alias as the events' target.Type: Boolean Required: No Default: FalseAWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent. 
- 
					Definition
- 
					The state machine definition is an object, where the format of the object matches the format of your AWS SAM template file, for example, JSON or YAML. State machine definitions adhere to the Amazon States Language. For an example of an inline state machine definition, see Examples. You must provide either a Definitionor aDefinitionUri.Type: Map Required: Conditional AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent. 
- 
					DefinitionSubstitutions
- 
					A string-to-string map that specifies the mappings for placeholder variables in the state machine definition. This enables you to inject values obtained at runtime (for example, from intrinsic functions) into the state machine definition. Type: Map Required: No AWS CloudFormation compatibility: This property is similar to the DefinitionSubstitutionsproperty of anAWS::StepFunctions::StateMachineresource. If any intrinsic functions are specified in an inline state machine definition, AWS SAM adds entries to this property to inject them into the state machine definition.
- 
					DefinitionUri
- 
					The Amazon Simple Storage Service (Amazon S3) URI or local file path of the state machine definition written in the Amazon States Language. If you provide a local file path, the template must go through the workflow that includes the sam deployorsam packagecommand to correctly transform the definition. To do this, you must use version 0.52.0 or later of the AWS SAM CLI.You must provide either a Definitionor aDefinitionUri.Type: String | S3Location Required: Conditional AWS CloudFormation compatibility: This property is passed directly to the DefinitionS3Locationproperty of anAWS::StepFunctions::StateMachineresource.
- 
					DeploymentPreference
- 
					The settings that enable and configure gradual state machine deployments. To learn more about Step Functions gradual deployments, see Manage continuous deployments with versions and aliases in the AWS Step Functions Developer Guide. Specify AutoPublishAliasbefore configuring this property. YourDeploymentPreferencesettings will be applied to the alias specified withAutoPublishAlias.When you specify DeploymentPreference, AWS SAM generates theStateMachineVersionArnsub-property value automatically.Type: DeploymentPreference Required: No AWS CloudFormation compatibility: AWS SAM generates and attaches the StateMachineVersionArnproperty value toDeploymentPreferenceand passesDeploymentPreferenceto theDeploymentPreferenceproperty of anAWS::StepFunctions::StateMachineAliasresource.
- 
					Events
- 
					Specifies the events that trigger this state machine. Events consist of a type and a set of properties that depend on the type. Type: EventSource Required: No AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent. 
- 
					Logging
- 
					Defines which execution history events are logged and where they are logged. Type: LoggingConfiguration Required: No AWS CloudFormation compatibility: This property is passed directly to the LoggingConfigurationproperty of anAWS::StepFunctions::StateMachineresource.
- 
					Name
- 
					The name of the state machine. Type: String Required: No AWS CloudFormation compatibility: This property is passed directly to the StateMachineNameproperty of anAWS::StepFunctions::StateMachineresource.
- 
					PermissionsBoundary
- 
					The ARN of a permissions boundary to use for this state machine's execution role. This property only works if the role is generated for you. Type: String Required: No AWS CloudFormation compatibility: This property is passed directly to the PermissionsBoundaryproperty of anAWS::IAM::Roleresource.
- 
					Policies
- 
					Permission policies for this state machine. Policies will be appended to the state machine's default AWS Identity and Access Management (IAM) execution role. This property accepts a single value or list of values. Allowed values include: 
- 
							The ARN of an AWS managed policy or customer managed policy. 
- 
							The name of an AWS managed policy from the following list . 
- 
							An inline IAM policy formatted in YAML as a map. 
 NoteIf you set the Roleproperty, this property is ignored.Type: String | List | Map Required: No AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent. 
- 
					Indicate whether or not to pass tags from the Tagsproperty to your AWS::Serverless::StateMachine generated resources. SpecifyTrueto propagate tags in your generated resources.Type: Boolean Required: No Default: FalseAWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent. 
- 
					Role
- 
					The ARN of an IAM role to use as this state machine's execution role. Type: String Required: Conditional AWS CloudFormation compatibility: This property is passed directly to the RoleArnproperty of anAWS::StepFunctions::StateMachineresource.
- 
					RolePath
- 
					The path to the state machine's IAM execution role. Use this property when the role is generated for you. Do not use when the role is specified with the Roleproperty.Type: String Required: Conditional AWS CloudFormation compatibility: This property is passed directly to the Pathproperty of anAWS::IAM::Roleresource.
- 
					A string-to-string map that specifies the tags added to the state machine and the corresponding execution role. For information about valid keys and values for tags, see the Tags property of an AWS::StepFunctions::StateMachine resource. Type: Map Required: No AWS CloudFormation compatibility: This property is similar to the Tagsproperty of anAWS::StepFunctions::StateMachineresource. AWS SAM automatically adds astateMachine:createdBy:SAMtag to this resource, and to the default role that is generated for it.
- 
					Tracing
- 
					Selects whether or not AWS X-Ray is enabled for the state machine. For more information about using X-Ray with Step Functions, see AWS X-Ray and Step Functions in the AWS Step Functions Developer Guide. Type: TracingConfiguration Required: No AWS CloudFormation compatibility: This property is passed directly to the TracingConfigurationproperty of anAWS::StepFunctions::StateMachineresource.
- 
					Type
- 
					The type of the state machine. Valid values: STANDARDorEXPRESSType: String Required: No Default: STANDARDAWS CloudFormation compatibility: This property is passed directly to the StateMachineTypeproperty of anAWS::StepFunctions::StateMachineresource.
Return Values
Ref
When you provide the logical ID of this resource to the Ref intrinsic function, Ref
				returns the Amazon Resource Name (ARN) of the underlying
					AWS::StepFunctions::StateMachine resource.
For more information about using the Ref function, see Ref in the AWS CloudFormation User Guide. 
Fn::GetAtt
Fn::GetAtt returns a value for a specified attribute of this type. The
				following are the available attributes and sample return values. 
For more information about using Fn::GetAtt, see Fn::GetAtt in the AWS CloudFormation User Guide. 
- Name
- 
						Returns the name of the state machine, such as HelloWorld-StateMachine.
Examples
State Machine Definition File
The following is an example of an inline state machine definition that allows a lambda function to invoke state machine. 
				Note that this example expects the Role property to configure proper policy to allow invocation.
				The my_state_machine.asl.json file must be written in the Amazon
					States Language.
In this example, the DefinitionSubstitution entries allow the state machine
				to include resources that are declared in the AWS SAM template file.
YAML
MySampleStateMachine: Type: AWS::Serverless::StateMachine Properties: DefinitionUri: statemachine/my_state_machine.asl.json Role: arn:aws:iam::123456123456:role/service-role/my-sample-role Tracing: Enabled: true DefinitionSubstitutions: MyFunctionArn: !GetAtt MyFunction.Arn MyDDBTable: !Ref TransactionTable
Inline State Machine Definition
The following is an example of an inline state machine definition.
In this example, the AWS SAM template file is written in YAML, so the state machine definition is also in YAML. To declare an inline state machine definition in JSON, write your AWS SAM template file in JSON.
YAML
MySampleStateMachine: Type: AWS::Serverless::StateMachine Properties: Definition: StartAt: MyLambdaState States: MyLambdaState: Type: Task Resource: arn:aws:lambda:us-east-1:123456123456:function:my-sample-lambda-app End: true Role: arn:aws:iam::123456123456:role/service-role/my-sample-role Tracing: Enabled: true