

终止支持通知：2026 年 10 月 7 日， AWS 将终止对的支持。 AWS Proton 2026 年 10 月 7 日之后，您将无法再访问 AWS Proton 控制台或 AWS Proton 资源。您部署的基础架构将保持不变。有关更多信息，请参阅《[AWS Proton 服务弃用和迁移指南》](https://docs.aws.amazon.com/proton/latest/userguide/proton-end-of-support.html)。

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

# 更新服务实例
<a name="ag-svc-instance-update"></a>

学习更新 AWS Proton 服务实例并取消更新。

服务实例属于服务。您只能在服务[编辑](ag-svc-update.md)、[创建](ag-create-svc.md)和[删除](ag-svc-delete.md)操作的上下文中创建或删除实例。要了解如何在服务中添加和删除实例，请参阅[编辑服务](ag-svc-update.md)。

可以使用 4 种模式更新服务实例，如以下列表中所述。使用时 AWS CLI，该`deployment-type`字段定义了模式。在使用控制台时，这些模式映射到服务实例详细信息页面上的**操作**下拉列表中的**编辑**和**更新到最新的次要版本**以及**更新到最新的主要版本**操作。

  
`NONE`  
在该模式下，*不会* 进行部署。仅更新请求的元数据参数。

  
`CURRENT_VERSION`  
在该模式下，将使用您提供的新规范部署和更新服务实例。仅更新请求的参数。在使用该 `deployment-type` 时，*不要* 包含次要或主要版本参数。

  
`MINOR_VERSION`  
在该模式下，默认使用当前使用的主要版本的已发布推荐（最新）次要版本部署和更新服务实例。您也可以指定当前使用的主要版本的不同次要版本。

  
`MAJOR_VERSION`  
在该模式下，默认使用当前模板的已发布推荐（最新）主要版本和次要版本部署和更新服务实例。您也可以指定高于正在使用的主要版本的不同主要版本和次要版本（可选）。

如果`deploymentStatus`是，则可以尝试取消服务实例更新部署`IN_PROGRESS`。 AWS Proton 试图取消部署。*不能* 保证成功取消。

取消更新部署时， AWS Proton 会尝试取消部署，如以下步骤所示。
+ 将部署状态设置为 `CANCELLING`。
+ 停止正在进行的部署，并删除状态为 `IN_PROGRESS` 时部署创建的任何新资源。
+ 将部署状态设置为 `CANCELLED`。
+ 将资源状态恢复为开始部署之前的状态。

有关取消服务实例部署的更多信息，请参阅 *AWS Proton API 参考[CancelServiceInstanceDeployment](https://docs.aws.amazon.com/proton/latest/APIReference/API_CancelServiceInstanceDeployment.html)*中的。

**使用控制台或 AWS CLI 进行更新或取消更新部署。**

------
#### [ AWS 管理控制台 ]

**按照以下步骤，使用控制台更新服务实例。**

1. 在 [AWS Proton 控制台](https://console.aws.amazon.com//proton/)中，在导航窗格中选择**服务实例**。

1. 在服务实例列表中，选择要更新的服务实例的名称。

1. 选择**操作**，然后选择更新选项之一：**编辑**（用于更新规范）、**更新到最新的次要版本**或**更新到最新的主要版本**。****

1. 填写每个表单并选择**下一步**，直至到达**审核**页面。

1. 检查您的编辑内容并选择**更新**。

------
#### [ AWS CLI ]

**将服务实例更新为新的次要版本，如 CLI 示例命令和响应中所示。**

在您使用修改的 `spec` 更新服务实例时，您可以使用 `"${Proton::CURRENT_VAL}"` 指示要在原始 `spec` 中保留哪些参数值（如果这些值在 `spec` 中存在）。可以使用 `get-service` 查看服务实例的原始 `spec`，如[查看服务数据](ag-svc-view.md)中所述。

以下示例说明了如何在 `spec` 中使用 `"${Proton::CURRENT_VAL}"`。

规范：

```
proton: ServiceSpec

pipeline:
  my_sample_pipeline_optional_input: "${Proton::CURRENT_VAL}"
  my_sample_pipeline_required_input: "${Proton::CURRENT_VAL}"

instances:
  - name: "my-instance"
    environment: "simple-env"
    spec:
      my_sample_service_instance_optional_input: "${Proton::CURRENT_VAL}"
      my_sample_service_instance_required_input: "${Proton::CURRENT_VAL}"
  - name: "my-other-instance"
    environment: "simple-env"
    spec:
      my_sample_service_instance_required_input: "789"
```

命令：更新

```
$ aws proton update-service-instance \
    --name "instance-one" \
    --service-name "simple-svc" \
    --spec "file://service-spec.yaml" \
    --template-major-version "1" \
    --template-minor-version "1" \
    --deployment-type "MINOR_VERSION"
```

响应：

```
{
    "serviceInstance": {
        "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one",
        "createdAt": "2021-04-02T21:29:59.962000+00:00",
        "deploymentStatus": "IN_PROGRESS",
        "environmentName": "arn:aws:proton:region-id:123456789012:environment/simple-env",
        "lastDeploymentAttemptedAt": "2021-04-02T21:38:00.823000+00:00",
        "lastDeploymentSucceededAt": "2021-04-02T21:29:59.962000+00:00",
        "name": "instance-one",
        "serviceName": "simple-svc",
        "templateMajorVersion": "1",
        "templateMinorVersion": "0",
        "templateName": "svc-simple"
    }
}
```

命令：获取并确认状态

```
$ aws proton get-service-instance \
    --name "instance-one" \
    --service-name "simple-svc"
```

响应：

```
{
    "serviceInstance": {
        "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one",
        "createdAt": "2021-04-02T21:29:59.962000+00:00",
        "deploymentStatus": "SUCCEEDED",
        "environmentName": "simple-env",
        "lastDeploymentAttemptedAt": "2021-04-02T21:38:00.823000+00:00",
        "lastDeploymentSucceededAt": "2021-04-02T21:38:00.823000+00:00",
        "name": "instance-one",
        "serviceName": "simple-svc",
        "spec": "proton: ServiceSpec\n\npipeline:\n  my_sample_pipeline_optional_input: \"abc\"\n  my_sample_pipeline_required_input: \"123\"\n\ninstances:\n  - name: \"instance-one\"\n    environment: \"simple-env\"\n    spec:\n      my_sample_service_instance_optional_input: \"def\"\n      my_sample_service_instance_required_input: \"456\"\n  - name: \"my-other-instance\"\n    environment: \"kls-simple-env\"\n    spec:\n      my_sample_service_instance_required_input: \"789\"\n",
        "templateMajorVersion": "1",
        "templateMinorVersion": "1",
        "templateName": "svc-simple"
    }
}
```

------

------
#### [ AWS 管理控制台 ]

**使用控制台取消服务实例部署，如以下步骤中所示。**

1. 在 [AWS Proton 控制台](https://console.aws.amazon.com//proton/)中，在导航窗格中选择**服务实例**。

1. 在服务实例列表中，选择包含要取消的部署更新的服务实例的名称。

1. 如果您的更新部署状态为**进行中**，请在服务实例详细信息页面中选择**操作**，然后选择**取消部署**。

1. 一个模态框要求您确认取消。选择**取消部署**。

1. 您的更新部署状态设置为**正在取消**，然后设置为**已取消**以完成取消。

------
#### [ AWS CLI ]

**取消将 IN\$1PROGRESS 服务实例部署更新为新的次要版本 2，如以下 CLI 示例命令和响应中所示。**

在用于该示例的模板中包含一个等待条件，以便在更新部署成功之前开始取消。

命令：取消

```
$ aws proton cancel-service-instance-deployment \
    --service-instance-name "instance-one" \
    --service-name "simple-svc"
```

响应：

```
{
    "serviceInstance": {
        "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one",
        "createdAt": "2021-04-02T21:29:59.962000+00:00",
        "deploymentStatus": "CANCELLING",
        "environmentName": "simple-env",
        "lastDeploymentAttemptedAt": "2021-04-02T21:45:15.406000+00:00",
        "lastDeploymentSucceededAt": "2021-04-02T21:38:00.823000+00:00",
        "name": "instance-one",
        "serviceName": "simple-svc",
        "spec": "proton: ServiceSpec\npipeline:\n  my_sample_pipeline_optional_input: abc\n  my_sample_pipeline_required_input: '123'\ninstances:\n- name: my-instance\n  environment: MySimpleEnv\n  spec:\n    my_sample_service_instance_optional_input: def\n    my_sample_service_instance_required_input: '456'\n- name: my-other-instance\n  environment: MySimpleEnv\n  spec:\n    my_sample_service_instance_required_input: '789'\n",
        "templateMajorVersion": "1",
        "templateMinorVersion": "1",
        "templateName": "svc-simple"
    }
}
```

命令：获取并确认状态

```
$ aws proton get-service-instance \
    --name "instance-one" \
    --service-name "simple-svc"
```

响应：

```
{
    "serviceInstance": {
        "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one",
        "createdAt": "2021-04-02T21:29:59.962000+00:00",
        "deploymentStatus": "CANCELLED",
        "deploymentStatusMessage": "User initiated cancellation.",
        "environmentName": "simple-env",
        "lastDeploymentAttemptedAt": "2021-04-02T21:45:15.406000+00:00",
        "lastDeploymentSucceededAt": "2021-04-02T21:38:00.823000+00:00",
        "name": "instance-one",
        "serviceName": "simple-svc",
        "spec": "proton: ServiceSpec\n\npipeline:\n  my_sample_pipeline_optional_input: \"abc\"\n  my_sample_pipeline_required_input: \"123\"\n\ninstances:\n  - name: \"instance-one\"\n    environment: \"simple-env\"\n    spec:\n      my_sample_service_instance_optional_input: \"def\"\n      my_sample_service_instance_required_input: \"456\"\n  - name: \"my-other-instance\"\n    environment: \"kls-simple-env\"\n    spec:\n      my_sample_service_instance_required_input: \"789\"\n",
        "templateMajorVersion": "1",
        "templateMinorVersion": "1",
        "templateName": "svc-simple"
    }
}
```

------