AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

AWS::StepFunctions::StateMachine

使用 AWS::StepFunctions::StateMachine 资源创建 AWS Step Functions 状态机。

注意

AWS CloudFormation 自动为您的状态机生成名称。如果您更改 DefinitionStringRoleArn 属性的内容并更新堆栈,AWS CloudFormation 会生成新的状态机名称并删除旧的状态机。

有关创建状态机的信息,请参阅 AWS Step Functions 开发人员指南中的教程:Lambda 状态机AWS Step Functions API 参考中的 CreateStateMachine

语法

JSON

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

YAML

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

属性

DefinitionString

状态机的 Amazon 状态语言 定义。有关更多信息,请参阅 AWS Step Functions 开发人员指南中的 Amazon 状态语言

Required: Yes

Type: String

更新要求替换

RoleArn

这个状态机使用的 IAM 角色的 Amazon 资源名称 (ARN)。

Required: Yes

Type: String

更新要求替换

返回值

Ref

当向 Ref 内部函数提供此资源的逻辑 ID 时,Ref 将返回所创建状态机的 ARN。例如:

Copy
{ "Ref": "MyStateMachine" }

返回与以下值类似的值:

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

有关使用 Ref 功能的更多信息,请参阅参考

Fn::GetAtt

Fn::GetAtt 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

Name

返回状态机的名称。例如:

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

返回与以下值类似的值:

Copy
MyStateMachine-ABCDEFGHIJ1K

有关使用 Fn::GetAtt 的更多信息,请参见 Fn::GetAtt

示例

以下示例创建 Step Functions 状态机。

JSON

使用单行属性

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" } } } }

使用 Fn::Join 内部函数

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

本页内容: