AWS::Serverless::StateMachine - Amazon Serverless Application Model
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS::Serverless::StateMachine

创建Amazon Step Functions状态机,您可以使用它来协调Amazon Lambda函数和其他Amazon资源,以形成复杂而强大的工作流程。

有关 Step Functions 的更多信息,请参阅 Amazon Step Functions 开发人员指南

注意

当您部署到时Amazon CloudFormation,Amazon SAM会将您的Amazon SAM资源转换为Amazon CloudFormation资源。有关更多信息,请参阅Amazon CloudFormation

语法

要在Amazon Serverless Application Model(Amazon SAM)模板中声明此实体,请使用以下语法()。

YAML

Type: AWS::Serverless::StateMachine Properties: Definition: Map DefinitionSubstitutions: Map DefinitionUri: String | S3Location Events: EventSource Logging: LoggingConfiguration Name: String PermissionsBoundary: String Policies: String | List | Map RolePath: String Role: String Tags: Map Tracing: TracingConfiguration Type: String

属性

Definition

状态机定义是一个对象,其中的对象格式与 Amazon SAM 模板文件的格式相匹配,例如 JSON 或 YAML。状态机定义遵循 Amazon 状态语言

有关行内状态机定义的示例,请参见示例

您必须提供 aDefinition 或 aDefinitionUri

类型:地图

必需:条件

Amazon CloudFormation兼容性:此属性是唯一的Amazon SAM,没有Amazon CloudFormation等效属性。

DefinitionSubstitutions

指定状态机定义中占位符变量的映射。 string-to-string 这使您可以将运行时获得的值(例如,从内部函数中)。

类型:地图

必需:否

Amazon CloudFormation兼容性:此属性类似于AWS::StepFunctions::StateMachine资源的DefinitionSubstitutions属性。如果在行内状态机定义中指定了任何内部函数,则向该属性Amazon SAM添加条目以将其注入状态机定义。

DefinitionUri

状态机的 Amazon Simple Storage Service (Amazon S3) 的 Amazon S3)

如果您提供本地文件路径,则模板必须通过包含sam deploysam package命令的工作流程才能正确转换定义。要执行此操作,必须使用 CLI 的 0.52.0 或更高版本的Amazon SAM CLI 的 0.52.0 或更高版本。

您必须提供 aDefinition 或 aDefinitionUri

类型:字符串 | S3Location

必需:条件

Amazon CloudFormation兼容性:此属性直接传递给AWS::StepFunctions::StateMachine资源的DefinitionS3Location属性。

Events

指定触发此状态机的事件。事件由一种类型和一组依赖于该类型的属性组成。

类型EventSource

必需:否

Amazon CloudFormation兼容性:此属性是唯一的Amazon SAM,没有Amazon CloudFormation等效属性。

Logging

定义记录哪些执行历史事件以及它们的记录位置。

类型LoggingConfiguration

必需:否

Amazon CloudFormation兼容性:此属性直接传递给AWS::StepFunctions::StateMachine资源的LoggingConfiguration属性。

Name

状态机的名称。

类型:字符串

必需:否

Amazon CloudFormation兼容性:此属性直接传递给AWS::StepFunctions::StateMachine资源的StateMachineName属性。

PermissionsBoundary

这个状态机的 ARN。只有在为你生成角色时,此属性才有效。

类型:字符串

必需:否

Amazon CloudFormation兼容性:此属性直接传递给AWS::IAM::Role资源的PermissionsBoundary属性。

Policies

此状态机的执行角色需要的一个或多个策略。

此属性接受一个字符串或字符串列表。该属性可以是Amazon托管Amazon Identity and Access Management (IAM) 策略的名称、Amazon SAM策略模板或一个或多个格式化为地图的内联策略文档。

如果设置了该Role属性,将忽略该属性。

类型:字符串 | 列表 | 地图

必需:条件

Amazon CloudFormation兼容性:此属性是唯一的Amazon SAM,没有Amazon CloudFormation等效属性。

Role

用作此状态机的 IAAM 角色的 IAAM 角色的 ARN。

类型:字符串

必需:条件

Amazon CloudFormation兼容性:此属性直接传递给AWS::StepFunctions::StateMachine资源的 RoleArn属性。

RolePath

状态机的 IAM 执行角色的路径。

在为您生成角色时使用此属性。在使用Role属性指定角色时不要使用。

类型:字符串

必需:条件

Amazon CloudFormation兼容性:此属性直接传递给AWS::IAM::Role资源的Path属性。

Tags

一个 string-to-string 地图,用于指定添加到状态机的标签和相应的执行角色。有关标签的有效键和值的信息,请参阅AWS::StepFunctions::StateMachine资源的 Tags 属性。

类型:地图

必需:否

Amazon CloudFormation兼容性:此属性类似于AWS::StepFunctions::StateMachine资源的Tags属性。 Amazon SAM自动向该资源以及为其生成的默认角色添加stateMachine:createdBy:SAM标签。

Tracing

选择Amazon X-Ray是否启用状态机的。有关将 X-Ray 与步进函数结合使用的更多信息,请参阅Amazon Step Functions开发人员指南中的Amazon X-Ray和St ep Functions

类型TracingConfiguration

必需:否

Amazon CloudFormation兼容性:此属性直接传递给AWS::StepFunctions::StateMachine资源的TracingConfiguration属性。

Type

The type of the state machine.

有效值STANDARDEXPRESS

类型:字符串

必需:否

默认值STANDARD

Amazon CloudFormation兼容性:此属性直接传递给AWS::StepFunctions::StateMachine资源的StateMachineType属性。

返回值

Ref

当向 Ref 内部函数提供此资源的逻辑 ID 时,Ref 将返回底层AWS::StepFunctions::StateMachine资源的 Amazon 资源名称(ARN)。

有关使用该Ref函数的更多信息,请参阅RefAmazon CloudFormation用户指南》

Fn::GetAtt

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

有关使用的更多信息Fn::GetAtt,请参阅Fn::GetAttAmazon CloudFormation用户指南中的

Name

返回状态HelloWorld-StateMachine

示例

状态机定义文件

以下是使用定义定义定义定义的状态机的。该my_state_machine.asl.json文件必须使用亚马逊州语言编写。

在此示例中,DefinitionSubstitution条目允许状态机包含在Amazon SAM模板文件中声明的资源。

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

行内状态机定义

以下是内联状态机定义的。

在此示例中,Amazon SAM模板文件是用 YAML 编写的,因此状态机定义也在 YAML 中。要在 JSON 中声明内联状态机定义,请在 JSON 中编写您的Amazon SAM模板文件。

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