

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# 使用 的 Route 53 Profiles 範例 AWS CLI
<a name="cli_2_route53profiles_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Route 53 Profiles 執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

**Topics**
+ [動作](#actions)

## 動作
<a name="actions"></a>

### `associate-profile`
<a name="route53profiles_AssociateProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `associate-profile`。

**AWS CLI**  
**建立設定檔的關聯**  
下列 `associate-profile` 範例會將設定檔與 VPC 建立關聯。  

```
aws route53profiles associate-profile \
    --name test-association \
    --profile-id rp-4987774726example \
    --resource-id vpc-0af3b96b3example
```
輸出：  

```
{
    "ProfileAssociation": {
        "CreationTime": 1710851336.527,
        "Id": "rpassoc-489ce212fexample",
        "ModificationTime": 1710851336.527,
        "Name": "test-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceId": "vpc-0af3b96b3example",
        "Status": "CREATING",
        "StatusMessage": "Creating Profile Association"
    }
}
```
如需詳細資訊，請參閱《Amazon Route 53 開發人員指南》**中的[使用設定檔](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/profile-high-level-steps.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [AssociateProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/associate-profile.html)。

### `associate-resource-to-profile`
<a name="route53profiles_AssociateResourceToProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `associate-resource-to-profile`。

**AWS CLI**  
**將資源與設定檔建立關聯**  
下列 `associate-resource-to-profile` 範例會將優先順序為 102 的 DNS 防火牆規則群組與設定檔建立關聯。  

```
aws route53profiles associate-resource-to-profile \
    --name test-resource-association \
    --profile-id rp-4987774726example \
    --resource-arn arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example \
    --resource-properties "{\"priority\": 102}"
```
輸出：  

```
{
    "ProfileResourceAssociation": {
        "CreationTime": 1710851216.613,
        "Id": "rpr-001913120a7example",
        "ModificationTime": 1710851216.613,
        "Name": "test-resource-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceArn": "arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example",
        "ResourceProperties": "{\"priority\":102}",
        "ResourceType": "FIREWALL_RULE_GROUP",
        "Status": "UPDATING",
        "StatusMessage": "Updating the Profile to DNS Firewall rule group association"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [AssociateResourceToProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/associate-resource-to-profile.html)。

### `create-profile`
<a name="route53profiles_CreateProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `create-profile`。

**AWS CLI**  
**建立設定檔**  
下列 `create-profile` 範例會建立設定檔。  

```
aws route53profiles create-profile \
    --name test
```
輸出：  

```
{
    "Profile": {
        "Arn": "arn:aws:route53profiles:us-east-1:123456789012:profile/rp-6ffe47d5example",
        "ClientToken": "2ca1a304-32b3-4f5f-bc4c-EXAMPLE11111",
        "CreationTime": 1710850903.578,
        "Id": "rp-6ffe47d5example",
        "ModificationTime": 1710850903.578,
        "Name": "test",
        "OwnerId": "123456789012",
        "ShareStatus": "NOT_SHARED",
        "Status": "COMPLETE",
        "StatusMessage": "Created Profile"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/create-profile.html)。

### `delete-profile`
<a name="route53profiles_DeleteProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `delete-profile`。

**AWS CLI**  
**刪除設定檔**  
下列 `delete-profile` 範例會刪除設定檔。  

```
aws route53profiles delete-profile \
    --profile-id rp-6ffe47d5example
```
輸出：  

```
{
    "Profile": {
        "Arn": "arn:aws:route53profiles:us-east-1:123456789012:profile/rp-6ffe47d5example",
        "ClientToken": "0a15fec0-05d9-4f78-bec0-EXAMPLE11111",
        "CreationTime": 1710850903.578,
        "Id": "rp-6ffe47d5example",
        "ModificationTime": 1710850903.578,
        "Name": "test",
        "OwnerId": "123456789012",
        "ShareStatus": "NOT_SHARED",
        "Status": "DELETED",
        "StatusMessage": "Deleted Profile"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/delete-profile.html)。

### `disassociate-profile`
<a name="route53profiles_DisassociateProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `disassociate-profile`。

**AWS CLI**  
**取消設定檔的關聯**  
下列 `disassociate-profile` 範例會取消設定檔與 VPC 的關聯。  

```
aws route53profiles disassociate-profile \
    --profile-id rp-4987774726example \
    --resource-id vpc-0af3b96b3example
```
輸出：  

```
{
    "ProfileAssociation": {
        "CreationTime": 1710851336.527,
        "Id": "rpassoc-489ce212fexample",
        "ModificationTime": 1710851401.362,
        "Name": "test-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceId": "vpc-0af3b96b3example",
        "Status": "DELETING",
        "StatusMessage": "Deleting Profile Association"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DisassociateProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/disassociate-profile.html)。

### `disassociate-resource-from-profile`
<a name="route53profiles_DisassociateResourceFromProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `disassociate-resource-from-profile`。

**AWS CLI**  
**取消資源與設定檔的關聯**  
下列 `disassociate-resource-from-profile` 範例會取消 DNS 防火牆規則群組與設定檔的關聯。  

```
aws route53profiles disassociate-resource-from-profile \
    --profile-id rp-4987774726example \
    --resource-arn arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example
```
輸出：  

```
{
    "ProfileResourceAssociation": {
        "CreationTime": 1710851216.613,
        "Id": "rpr-001913120a7example",
        "ModificationTime": 1710852624.36,
        "Name": "test-resource-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceArn": "arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example",
        "ResourceProperties": "{\"priority\":105}",
        "ResourceType": "FIREWALL_RULE_GROUP",
        "Status": "DELETING",
        "StatusMessage": "Deleting the Profile to DNS Firewall rule group association"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DisassociateResourceFromProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/disassociate-resource-from-profile.html)。

### `get-profile-association`
<a name="route53profiles_GetProfileAssociation_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `get-profile-association`。

**AWS CLI**  
**取得設定檔關聯的相關資訊**  
下列 `get-profile-association` 會傳回指定設定檔關聯的相關資訊。  

```
aws route53profiles get-profile-association \
    --profile-association-id rpassoc-489ce212fexample
```
輸出：  

```
{
    "ProfileAssociation": {
        "CreationTime": 1709338817.148,
        "Id": "rrpassoc-489ce212fexample",
        "ModificationTime": 1709338974.772,
        "Name": "test-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceId": "vpc-0af3b96b3example",
        "Status": "COMPLETE",
        "StatusMessage": "Created Profile Association"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetProfileAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/get-profile-association.html)。

### `get-profile-resource-association`
<a name="route53profiles_GetProfileResourceAssociation_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `get-profile-resource-association`。

**AWS CLI**  
**取得與設定檔相關聯之資源的相關資訊**  
下列 `get-profile-resource-association` 會將指定資源關聯的相關資訊傳回至設定檔。  

```
aws route53profiles get-profile-resource-association \
    --profile-resource-association-id rpr-001913120a7example
```
輸出：  

```
{
    "ProfileResourceAssociation": {
        "CreationTime": 1710851216.613,
        "Id": "rpr-001913120a7example",
        "ModificationTime": 1710852303.798,
        "Name": "test-resource-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceArn": "arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example",
        "ResourceProperties": "{\"priority\":105}",
        "ResourceType": "FIREWALL_RULE_GROUP",
        "Status": "COMPLETE",
        "StatusMessage": "Completed creation of Profile to DNS Firewall rule group association"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetProfileResourceAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/get-profile-resource-association.html)。

### `get-profile`
<a name="route53profiles_GetProfile_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `get-profile`。

**AWS CLI**  
**取得設定檔的相關資訊**  
下列 `get-profile` 會傳回指定設定檔的相關資訊。  

```
aws route53profiles get-profile \
    --profile-id rp-4987774726example
```
輸出：  

```
{
    "Profile": {
        "Arn": "arn:aws:route53profiles:us-east-1:123456789012:profile/rp-4987774726example",
        "ClientToken": "0cbc5ae7-4921-4204-bea9-EXAMPLE11111",
        "CreationTime": 1710851044.288,
        "Id": "rp-4987774726example",
        "ModificationTime": 1710851044.288,
        "Name": "test",
        "OwnerId": "123456789012",
        "ShareStatus": "NOT_SHARED",
        "Status": "COMPLETE",
        "StatusMessage": "Created Profile"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetProfile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/get-profile.html)。

### `list-profile-associations`
<a name="route53profiles_ListProfileAssociations_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `list-profile-associations`。

**AWS CLI**  
**列出設定檔關聯**  
下列`list-profile-associations`列出您 AWS 帳戶中的設定檔關聯。  

```
aws route53profiles list-profile-associations
```
輸出：  

```
{
    "ProfileAssociations": [
        {
            "CreationTime": 1709338817.148,
            "Id": "rpassoc-489ce212fexample",
            "ModificationTime": 1709338974.772,
            "Name": "test-association",
            "OwnerId": "123456789012",
            "ProfileId": "rp-4987774726example",
            "ResourceId": "vpc-0af3b96b3example",
            "Status": "COMPLETE",
            "StatusMessage": "Created Profile Association"
        }
    ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListProfileAssociations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/list-profile-associations.html)。

### `list-profile-resource-associations`
<a name="route53profiles_ListProfileResourceAssociations_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `list-profile-resource-associations`。

**AWS CLI**  
**列出設定檔資源關聯**  
下列 `list-profile-resource-associations` 會列出指定設定檔的設定檔資源關聯。  

```
aws route53profiles list-profile-resource-associations \
    --profile-id rp-4987774726example
```
輸出：  

```
{
     "ProfileResourceAssociations": [
         {
             "CreationTime": 1710851216.613,
             "Id": "rpr-001913120a7example",
             "ModificationTime": 1710851216.613,
             "Name": "test-resource-association",
             "OwnerId": "123456789012",
             "ProfileId": "rp-4987774726example",
             "ResourceArn": "arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example",
             "ResourceProperties": "{\"priority\":102}",
             "ResourceType": "FIREWALL_RULE_GROUP",
             "Status": "COMPLETE",
             "StatusMessage": "Completed creation of Profile to DNS Firewall rule group association"
         }
     ]
 }
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListProfileResourceAssociations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/list-profile-resource-associations.html)。

### `list-profiles`
<a name="route53profiles_ListProfiles_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `list-profiles`。

**AWS CLI**  
**列出設定檔**  
以下`list-profiles`列出您 AWS 帳戶中的設定檔，並顯示這些設定檔的其他資訊。  

```
aws route53profiles list-profiles
```
輸出：  

```
{
     "ProfileSummaries": [
         {
             "Arn": "arn:aws:route53profiles:us-east-1:123456789012:profile/rp-4987774726example",
             "Id": "rp-4987774726example",
             "Name": "test",
             "ShareStatus": "NOT_SHARED"
         }
     ]
 }
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListProfiles](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/list-profiles.html)。

### `list-tags-for-resource`
<a name="route53profiles_ListTagsForResource_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `list-tags-for-resource`。

**AWS CLI**  
**列出資源的標籤**  
下列 `list-tags-for-resource` 會列出指定資源的標籤。  

```
aws route53profiles list-tags-for-resource \
    --resource-arn arn:aws:route53profiles:us-east-1:123456789012:profile/rp-4987774726example
```
輸出：  

```
{
    "Tags": {
        "my-key-2": "my-value-2",
        "my-key-1": "my-value-1"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/list-tags-for-resource.html)。

### `update-profile-resource-association`
<a name="route53profiles_UpdateProfileResourceAssociation_cli_2_topic"></a>

以下程式碼範例顯示如何使用 `update-profile-resource-association`。

**AWS CLI**  
**更新與設定檔相關聯的資源**  
下列 `update-profile-resource-association` 會更新與設定檔相關聯的 DNS 防火牆規則群組的優先順序。  

```
aws route53profiles update-profile-resource-association \
    --profile-resource-association-id rpr-001913120a7example \
    --resource-properties "{\"priority\": 105}"
```
輸出：  

```
{
    "ProfileResourceAssociation": {
        "CreationTime": 1710851216.613,
        "Id": "rpr-001913120a7example",
        "ModificationTime": 1710852303.798,
        "Name": "test-resource-association",
        "OwnerId": "123456789012",
        "ProfileId": "rp-4987774726example",
        "ResourceArn": "arn:aws:route53resolver:us-east-1:123456789012:firewall-rule-group/rslvr-frg-cfe7f72example",
        "ResourceProperties": "{\"priority\":105}",
        "ResourceType": "FIREWALL_RULE_GROUP",
        "Status": "UPDATING",
        "StatusMessage": "Updating the Profile to DNS Firewall rule group association"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateProfileResourceAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53profiles/update-profile-resource-association.html)。