使用 的 Route 53 設定檔範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

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

使用 的 Route 53 設定檔範例 AWS CLI

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

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

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

主題

動作

下列程式碼範例示範如何使用 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 開發人員指南中的使用設定檔

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 AssociateProfile

下列程式碼範例示範如何使用 associate-resource-to-profile

AWS CLI

將資源與設定檔建立關聯

下列associate-resource-to-profile範例會將優先順序為 102 的 DNS Firewall 規則群組與設定檔建立關聯。

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" } }

下列程式碼範例示範如何使用 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

下列程式碼範例示範如何使用 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

下列程式碼範例示範如何使用 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" } }

下列程式碼範例示範如何使用 disassociate-resource-from-profile

AWS CLI

取消資源與設定檔的關聯

下列disassociate-resource-from-profile範例會取消 DNS Firewall 規則群組與設定檔的關聯。

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" } }

下列程式碼範例示範如何使用 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" } }

下列程式碼範例示範如何使用 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" } }

下列程式碼範例示範如何使用 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

下列程式碼範例示範如何使用 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" } ] }

下列程式碼範例示範如何使用 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" } ] }

下列程式碼範例示範如何使用 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

下列程式碼範例示範如何使用 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" } }

下列程式碼範例示範如何使用 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" } }