

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Step Functions 工作流程中的狀態機器版本
<a name="concepts-state-machine-version"></a>

*版本*是狀態機器的編號、**不可變**快照。您可以發佈對該狀態機器所做的最新修訂的版本。每個版本都有唯一的 Amazon Resource Name (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_tw/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. 選擇 **Publish version (發佈版本)**。

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. 選擇 **Start execution (開始執行)**。

1. （選用） 在**開始執行**對話方塊中，輸入執行的名稱。

1. （選用） ，輸入執行輸入，然後選擇**開始執行**。