

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

# 修改您的應用程式
<a name="modify-application-using-api"></a>

AWS Resilience Hub 可讓您編輯應用程式的草稿版本，並將變更發佈至新的 （已發佈） 版本，以修改應用程式資源。 AWS Resilience Hub 會使用您應用程式的已發佈版本，其中包含更新的 資源，以執行彈性評估。

如需詳細資訊，請參閱下列主題：
+ [手動將資源新增至您的應用程式](#manually-add-resource-using-api)
+ [將資源分組到單一應用程式元件](#group-resource-using-api)
+ [從 AppComponent 排除資源](#exclude-resource-using-api)

## 手動將資源新增至您的應用程式
<a name="manually-add-resource-using-api"></a>

如果資源未部署為輸入來源的一部分， AWS Resilience Hub 可讓您使用 `CreateAppVersionResource` API 手動將資源新增至應用程式。如需這種 API 的詳細資訊，請參閱 [https://docs.aws.amazon.com/resilience-hub/latest/APIReference/API_CreateAppVersionResource.html](https://docs.aws.amazon.com/resilience-hub/latest/APIReference/API_CreateAppVersionResource.html)。

您必須提供下列參數給此 API：
+ 應用程式 Amazon Resource Name (ARN)
+ 資源的邏輯 ID
+ 資源的實體 ID
+ AWS CloudFormation 類型

下列範例示範如何使用 AWS Resilience Hub `CreateAppVersionResource` API 在 中手動將資源新增至您的應用程式。

### 請求
<a name="manually-add-resource-req"></a>

```
aws resiliencehub create-app-version-resource \
--app-arn <App_ARN> \
--resource-name "backup-efs" \
--logical-resource-id '{"identifier": "backup-efs"}' \
--physical-resource-id '<Physical_resource_id_ARN>' \
--resource-type AWS::EFS::FileSystem \
--app-components '["new-app-component"]'
```

### 回應
<a name="manually-add-resource-res"></a>

```
{
    "appArn": "<App_ARN>",
    "appVersion": "draft",
    "physicalResource": {
        "resourceName": "backup-efs",
        "logicalResourceId": {
            "identifier": "backup-efs"
        },
        "physicalResourceId": {
            "identifier": "<Physical_resource_id_ARN>",
            "type": "Arn"
        },
        "resourceType": "AWS::EFS::FileSystem",
        "appComponents": [
            {
                "name": "new-app-component",
                "type": "AWS::ResilienceHub::StorageAppComponent",
                "id": "new-app-component"
            }
        ]
    }
}
```

## 將資源分組到單一應用程式元件
<a name="group-resource-using-api"></a>

應用程式元件 (AppComponent) 是一組相關 AWS 資源，可做為單一單位運作並失敗。例如，當您有用作待命部署的跨區域工作負載時。 AWS Resilience Hub 具有管理哪些 AWS 資源可以屬於哪種 AppComponent 類型的規則。 AWS Resilience Hub 可讓您使用下列資源管理 APIs 將資源分組到單一 AppComponent。
+ `UpdateAppVersionResource` – 此 API 會更新應用程式的資源詳細資訊。如需此 API 的詳細資訊，請參閱 [UpdateAppVersionResource](https://docs.aws.amazon.com/resilience-hub/latest/APIReference/API_UpdateAppVersionResource.html)。
+ `DeleteAppVersionAppComponent` – 此 API 會從應用程式刪除 AppComponent。如需此 API 的詳細資訊，請參閱 [DeleteAppVersionAppComponent](https://docs.aws.amazon.com/resilience-hub/latest/APIReference/API_DeleteAppVersionAppComponent.html)。

下列範例示範如何使用 AWS Resilience Hub `DeleteAppVersionAppComponent` API 在 中更新應用程式的資源詳細資訊。

### 請求
<a name="update-resource-req"></a>

```
aws resiliencehub delete-app-version-app-component \
--app-arn <App_ARN> \
--id new-app-component
```

### 回應
<a name="update-resource-res"></a>

```
{
    "appArn": "<App_ARN>",
    "appVersion": "draft",
    "appComponent": {
        "name": "new-app-component",
        "type": "AWS::ResilienceHub::StorageAppComponent",
        "id": "new-app-component"
    }
}
```

下列範例顯示如何使用 AWS Resilience Hub `UpdateAppVersionResource` API 刪除在先前範例中建立的空 AppComponent。

### 請求
<a name="delete-appComp-req"></a>

```
aws resiliencehub delete-app-version-app-component \
--app-arn <App_ARN> \
--id new-app-component
```

### 回應
<a name="delete-appComp-res"></a>

```
{
    "appArn": "<App_ARN>",
    "appVersion": "draft",
    "appComponent": {
        "name": "new-app-component",
        "type": "AWS::ResilienceHub::StorageAppComponent",
        "id": "new-app-component"
    }
}
```

## 從 AppComponent 排除資源
<a name="exclude-resource-using-api"></a>

AWS Resilience Hub 可讓您使用 `UpdateAppVersionResource` API 從評估中排除資源。運算應用程式的彈性時，不會考慮這些資源。如需這種 API 的詳細資訊，請參閱 [https://docs.aws.amazon.com/resilience-hub/latest/APIReference/API_UpdateAppVersionResource.html](https://docs.aws.amazon.com/resilience-hub/latest/APIReference/API_UpdateAppVersionResource.html)。

**注意**  
您只能排除從輸入來源匯入的資源。

下列範例顯示如何使用 AWS Resilience Hub `UpdateAppVersionResource` API 在 中排除應用程式的資源。

### 請求
<a name="update-appComp-resource-req"></a>

```
aws resiliencehub update-app-version-resource \
--app-arn <App_ARN> \
--resource-name "ec2instance-nvz" \
--excluded
```

### 回應
<a name="update-appComp-resource-res"></a>

```
{
    "appArn": "<App_ARN>",
    "appVersion": "draft",
    "physicalResource": {
        "resourceName": "ec2instance-nvz",
        "logicalResourceId": {
            "identifier": "ec2",
            "terraformSourceName": "test.state.file"
        },
        "physicalResourceId": {
            "identifier": "i-0b58265a694e5ffc1",
            "type": "Native",
            "awsRegion": "us-west-2",
            "awsAccountId": "123456789101"
        },
        "resourceType": "AWS::EC2::Instance",
        "appComponents": [
            {
                "name": "computeappcomponent-nrz",
                "type": "AWS::ResilienceHub::ComputeAppComponent"
            }
        ]
    }
}
```