

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

# Step Functions 工作流程中的状态机版本
<a name="concepts-state-machine-version"></a>

*版本* 是状态机的快照，带编号且**不可变**。您可以从该状态机的最新修订版开始发布版本。每个版本都有一个唯一的 Amazon 资源名称（ARN），这是状态机 ARN 和版本号的组合，用冒号（:）分隔。以下示例显示状态机版本 ARN 的格式。

```
arn:partition:states:region:account-id:stateMachine:myStateMachine:1
```

要开始使用状态机版本，必须发布第一个版本。发布版本后，您可以使用版本 ARN 调用 [StartExecution](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html)API 操作。您无法编辑版本，但可以更新状态机并发布新版本。您也可以发布多个状态机版本。

![\[模糊的说明性图表显示了版本如何成为状态机的不可变快照。\]](http://docs.aws.amazon.com/zh_cn/step-functions/latest/dg/images/versioning-concept.png)


发布状态机的新版本时，Step Functions 会为其分配一个版本号。版本号从 1 开始，每个新版本都会单调递增。对于给定的状态机，版本号不会重复使用。如果您删除了状态机的版本 10，然后发布了新版本，Step Functions 会将其发布为版本 11。

状态机的所有版本的以下属性都相同：
+ 状态机的所有版本共享相同的类型[（标准或快速）](choosing-workflow-type.md)。
+ 您无法更改不同版本之间状态机的名称或创建日期。
+ 标签全局适用于状态机。您可以使用[TagResource](https://docs.aws.amazon.com/step-functions/latest/apireference/API_TagResource.html)和 [UntagResource](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UntagResource.html)API 操作管理状态机的标签。

状态机还包含作为每个版本和[revision](concepts-cd-aliasing-versioning.md#statemachinerev)一部分的属性，但这些属性在两个给定版本或修订版之间可能不同。这些属性包括[状态机定义](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachine.html#StepFunctions-UpdateStateMachine-request-definition)、[IAM 角色](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachine.html#StepFunctions-UpdateStateMachine-request-roleArn)、[跟踪配置](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachine.html#StepFunctions-UpdateStateMachine-request-tracingConfiguration)和[日志配置](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachine.html#StepFunctions-UpdateStateMachine-request-loggingConfiguration)。

## 发布状态机版本（控制台）
<a name="procedure-create-versions"></a>

您最多可以发布 1000 个版本的状态机。要请求提高此软限制，请使用 [AWS 管理控制台](https://docs.aws.amazon.com/servicequotas/latest/userguide/request-quota-increase.html)中的**支持中心**页面。您可以从控制台手动删除未使用的版本，也可以通过调用 [DeleteStateMachineVersion](https://docs.aws.amazon.com/step-functions/latest/apireference/API_DeleteStateMachineVersion.html)API 操作来删除未使用的版本。

**发布状态机版本的操作步骤**

1. 打开 [Step Functions 控制台](https://console.aws.amazon.com/states/home?region=us-east-1#/)，然后选择一个现有的状态机。

1. 在**状态机详细信息**页面上，选择**编辑**。

1. 根据需要编辑状态机定义，然后选择**保存**。

1. 选择**发布版本**。

1. （可选）在出现的对话框的**描述**字段中，输入有关状态机版本的简短描述。

1. 选择**发布**。

**注意**  
发布状态机的新版本时，Step Functions 会为其分配一个版本号。版本号从 1 开始，每个新版本都会单调递增。对于给定的状态机，版本号不会重复使用。如果您删除了状态机的版本 10，然后发布了新版本，Step Functions 会将其发布为版本 11。

## 使用 Step Functions API 操作管理版本
<a name="manage-versions-with-api"></a>

Step Functions 提供了以下 API 操作来发布和管理状态机版本：
+ [PublishStateMachineVersion](https://docs.aws.amazon.com/step-functions/latest/apireference/API_PublishStateMachineVersion.html)— 从状态[revision](concepts-cd-aliasing-versioning.md#statemachinerev)机的当前版本发布一个版本。
+ [UpdateStateMachine](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachine.html)— 如果您更新状态机并在同一请求`true`中将`publish`参数设置为，则发布新的状态机版本。
+ [CreateStateMachine](https://docs.aws.amazon.com/step-functions/latest/apireference/API_CreateStateMachine.html)— 如果将`publish`参数设置为，则发布状态机的第一个修订版`true`。
+ [ListStateMachineVersions](https://docs.aws.amazon.com/step-functions/latest/apireference/API_ListStateMachineVersions.html)— 列出指定状态机 ARN 的版本。
+ [DescribeStateMachine](https://docs.aws.amazon.com/step-functions/latest/apireference/API_DescribeStateMachine.html)— 返回中指定的版本 ARN 的状态机版本详情。`stateMachineArn`
+ [DeleteStateMachineVersion](https://docs.aws.amazon.com/step-functions/latest/apireference/API_DeleteStateMachineVersion.html)— 删除状态机版本。

要`myStateMachine`使用发布名为的状态机的当前版本中的新版本 AWS Command Line Interface，请使用以下`publish-state-machine-version`命令：

```
aws stepfunctions publish-state-machine-version --state-machine-arn arn:aws:states:region:account-id:stateMachine:myStateMachine
```

该响应返回 `stateMachineVersionArn`。例如，前面的命令返回的响应为 `arn:aws:states:region:account-id:stateMachine:myStateMachine:1`。

**注意**  
发布状态机的新版本时，Step Functions 会为其分配一个版本号。版本号从 1 开始，每个新版本都会单调递增。对于给定的状态机，版本号不会重复使用。如果您删除了状态机的版本 10，然后发布了新版本，Step Functions 会将其发布为版本 11。

## 从控制台运行状态机版本
<a name="procedure-run-version"></a>

要开始使用状态机版本，必须先从当前状态机[revision](concepts-cd-aliasing-versioning.md#statemachinerev)中发布一个版本。要发布版本，请使用 Step Functions 控制台或调用 [PublishStateMachineVersion](https://docs.aws.amazon.com/step-functions/latest/apireference/API_PublishStateMachineVersion.html)API 操作。您还可以使用名为的可选参数来调用 [UpdateStateMachineAlias](https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachineAlias.html)API 操作`publish`来更新状态机并发布其版本。

您可以使用控制台或调用 [StartExecution](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html)API 操作并提供版本 ARN 来开始执行某个版本。您也可以使用[别名](concepts-state-machine-alias.md)开始执行某个版本。别名会根据其[路由配置](concepts-state-machine-alias.md#alias-routing-config)，会将流量路由到特定版本。

如果不使用版本就启动状态机执行，Step Functions 将使用状态机的最新版本进行执行。有关 Step Functions 如何将执行与版本关联的信息，请参阅[将执行与版本或别名关联](execution-alias-version-associate.md)。

**使用一个状态机版本启动执行**

1. 打开 [Step Functions 控制台](https://console.aws.amazon.com/states/home?region=us-east-1#/)，然后选择已为其发布一个或多个版本的现有状态机。要了解如何发布版本，请参阅[发布状态机版本（控制台）](#procedure-create-versions)。

1. 在**状态机详细信息**页面上，选择**版本**选项卡。

1. 在**设置**部分，执行以下操作：

   1. 选择要启动执行的版本。

   1. 选择**启动执行**。

1. （可选）在**启动执行**对话框中，输入执行名称。

1. （可选），输入执行输入，然后选择**启动执行**。