AWS Support 使用範例 AWS CLI - AWS Command Line Interface

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

AWS Support 使用範例 AWS CLI

下列程式碼範例說明如何使用 AWS Command Line Interface 與來執行動作及實作常見案例 AWS Support。

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

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

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

主題

動作

下列程式碼範例會示範如何使用add-attachments-to-set

AWS CLI

將貼附加入至集

下列add-attachments-to-set範例會將影像新增至集合,然後您可以為 AWS 帳戶中的支援案例指定該影像集。

aws support add-attachments-to-set \ --attachment-set-id "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE" \ --attachments fileName=troubleshoot-screenshot.png,data=base64-encoded-string

輸出:

{ "attachmentSetId": "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE", "expiryTime": "2020-05-14T17:04:40.790+0000" }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

下列程式碼範例會示範如何使用add-communication-to-case

AWS CLI

若要將通訊新增至案例

下列add-communication-to-case範例會將通訊新增至您 AWS 帳戶中的支援案例。

aws support add-communication-to-case \ --case-id "case-12345678910-2013-c4c1d2bf33c5cf47" \ --communication-body "I'm attaching a set of images to this case." \ --cc-email-addresses "myemail@example.com" \ --attachment-set-id "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE"

輸出:

{ "result": true }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

下列程式碼範例會示範如何使用create-case

AWS CLI

若要建立案例

下列create-case範例會為您的 AWS 帳戶建立支援案例。

aws support create-case \ --category-code "using-aws" \ --cc-email-addresses "myemail@example.com" \ --communication-body "I want to learn more about an AWS service." \ --issue-type "technical" \ --language "en" \ --service-code "general-info" \ --severity-code "low" \ --subject "Question about my account"

輸出:

{ "caseId": "case-12345678910-2013-c4c1d2bf33c5cf47" }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

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

下列程式碼範例會示範如何使用describe-attachment

AWS CLI

描述附件

下列describe-attachment範例會傳回有關具有指定 ID 之附件的資訊。

aws support describe-attachment \ --attachment-id "attachment-KBnjRNrePd9D6Jx0-Mm00xZuDEaL2JAj_0-gJv9qqDooTipsz3V1Nb19rCfkZneeQeDPgp8X1iVJyHH7UuhZDdNeqGoduZsPrAhyMakqlc60-iJjL5HqyYGiT1FG8EXAMPLE"

輸出:

{ "attachment": { "fileName": "troubleshoot-screenshot.png", "data": "base64-blob" } }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

下列程式碼範例會示範如何使用describe-cases

AWS CLI

描述案例

下列describe-cases範例會傳回您 AWS 帳戶中指定支援案例的相關資訊。

aws support describe-cases \ --display-id "1234567890" \ --after-time "2020-03-23T21:31:47.774Z" \ --include-resolved-cases \ --language "en" \ --no-include-communications \ --max-item 1

輸出:

{ "cases": [ { "status": "resolved", "ccEmailAddresses": [], "timeCreated": "2020-03-23T21:31:47.774Z", "caseId": "case-12345678910-2013-c4c1d2bf33c5cf47", "severityCode": "low", "language": "en", "categoryCode": "using-aws", "serviceCode": "general-info", "submittedBy": "myemail@example.com", "displayId": "1234567890", "subject": "Question about my account" } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

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

下列程式碼範例會示範如何使用describe-communications

AWS CLI

描述案件的最新通訊

下列describe-communications範例會傳回您 AWS 帳戶中指定支援案例的最新通訊。

aws support describe-communications \ --case-id "case-12345678910-2013-c4c1d2bf33c5cf47" \ --after-time "2020-03-23T21:31:47.774Z" \ --max-item 1

輸出:

{ "communications": [ { "body": "I want to learn more about an AWS service.", "attachmentSet": [], "caseId": "case-12345678910-2013-c4c1d2bf33c5cf47", "timeCreated": "2020-05-12T23:12:35.000Z", "submittedBy": "Amazon Web Services" } ], "NextToken": "eyJuZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQEXAMPLE==" }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

下列程式碼範例會示範如何使用describe-services

AWS CLI

列出 AWS 服務和服務類別

下列describe-services範例會列出要求一般資訊的可用服務類別。

aws support describe-services \ --service-code-list "general-info"

輸出:

{ "services": [ { "code": "general-info", "name": "General Info and Getting Started", "categories": [ { "code": "charges", "name": "How Will I Be Charged?" }, { "code": "gdpr-queries", "name": "Data Privacy Query" }, { "code": "reserved-instances", "name": "Reserved Instances" }, { "code": "resource", "name": "Where is my Resource?" }, { "code": "using-aws", "name": "Using AWS & Services" }, { "code": "free-tier", "name": "Free Tier" }, { "code": "security-and-compliance", "name": "Security & Compliance" }, { "code": "account-structure", "name": "Account Structure" } ] } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

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

下列程式碼範例會示範如何使用describe-severity-levels

AWS CLI

列出可用的嚴重性層級

下列describe-severity-levels範例列出支援案例的可用嚴重性等級。

aws support describe-severity-levels

輸出:

{ "severityLevels": [ { "code": "low", "name": "Low" }, { "code": "normal", "name": "Normal" }, { "code": "high", "name": "High" }, { "code": "urgent", "name": "Urgent" }, { "code": "critical", "name": "Critical" } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的選擇嚴重性

下列程式碼範例會示範如何使用describe-trusted-advisor-check-refresh-statuses

AWS CLI

列出 AWS Trusted Advisor 檢查的重新整理狀態

下列describe-trusted-advisor-check-refresh-statuses範例列出兩個 Trusted Advisor 檢查的重新整理狀態:Amazon S3 儲存貯體許可和 IAM 使用。

aws support describe-trusted-advisor-check-refresh-statuses \ --check-id "Pfx0RwqBli" "zXCkfM1nI3"

輸出:

{ "statuses": [ { "checkId": "Pfx0RwqBli", "status": "none", "millisUntilNextRefreshable": 0 }, { "checkId": "zXCkfM1nI3", "status": "none", "millisUntilNextRefreshable": 0 } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的 AWS Trusted Advisor

下列程式碼範例會示範如何使用describe-trusted-advisor-check-result

AWS CLI

列出 AWS 信任的建議程式檢查結果

下列describe-trusted-advisor-check-result範例會列出 IAM 使用檢查的結果。

aws support describe-trusted-advisor-check-result \ --check-id "zXCkfM1nI3"

輸出:

{ "result": { "checkId": "zXCkfM1nI3", "timestamp": "2020-05-13T21:38:05Z", "status": "ok", "resourcesSummary": { "resourcesProcessed": 1, "resourcesFlagged": 0, "resourcesIgnored": 0, "resourcesSuppressed": 0 }, "categorySpecificSummary": { "costOptimizing": { "estimatedMonthlySavings": 0.0, "estimatedPercentMonthlySavings": 0.0 } }, "flaggedResources": [ { "status": "ok", "resourceId": "47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZEXAMPLE", "isSuppressed": false } ] } }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的 AWS Trusted Advisor

下列程式碼範例會示範如何使用describe-trusted-advisor-check-summaries

AWS CLI

列出 AWS 信任的建議程式檢查摘要

下列describe-trusted-advisor-check-summaries範例列出兩項 Trusted Advisor 檢查的結果:Amazon S3 儲存貯體許可和 IAM 使用。

aws support describe-trusted-advisor-check-summaries \ --check-ids "Pfx0RwqBli" "zXCkfM1nI3"

輸出:

{ "summaries": [ { "checkId": "Pfx0RwqBli", "timestamp": "2020-05-13T21:38:12Z", "status": "ok", "hasFlaggedResources": true, "resourcesSummary": { "resourcesProcessed": 44, "resourcesFlagged": 0, "resourcesIgnored": 0, "resourcesSuppressed": 0 }, "categorySpecificSummary": { "costOptimizing": { "estimatedMonthlySavings": 0.0, "estimatedPercentMonthlySavings": 0.0 } } }, { "checkId": "zXCkfM1nI3", "timestamp": "2020-05-13T21:38:05Z", "status": "ok", "hasFlaggedResources": true, "resourcesSummary": { "resourcesProcessed": 1, "resourcesFlagged": 0, "resourcesIgnored": 0, "resourcesSuppressed": 0 }, "categorySpecificSummary": { "costOptimizing": { "estimatedMonthlySavings": 0.0, "estimatedPercentMonthlySavings": 0.0 } } } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的 AWS Trusted Advisor

下列程式碼範例會示範如何使用describe-trusted-advisor-checks

AWS CLI

列出可用的「 AWS Trusted Advisor」檢查

下列describe-trusted-advisor-checks範例會列出您 AWS 帳戶中可用的 Trusted Advisor 檢查。此資訊包括檢查名稱、ID、描述、類別和中繼資料。請注意,輸出會縮短以提高可讀性。

aws support describe-trusted-advisor-checks \ --language "en"

輸出:

{ "checks": [ { "id": "zXCkfM1nI3", "name": "IAM Use", "description": "Checks for your use of AWS Identity and Access Management (IAM). You can use IAM to create users, groups, and roles in AWS, and you can use permissions to control access to AWS resources. \n<br>\n<br>\n<b>Alert Criteria</b><br>\nYellow: No IAM users have been created for this account.\n<br>\n<br>\n<b>Recommended Action</b><br>\nCreate one or more IAM users and groups in your account. You can then create additional users whose permissions are limited to perform specific tasks in your AWS environment. For more information, see <a href=\"https://docs.aws.amazon.com/IAM/latest/UserGuide/IAMGettingStarted.html\" target=\"_blank\">Getting Started</a>. \n<br><br>\n<b>Additional Resources</b><br>\n<a href=\"https://docs.aws.amazon.com/IAM/latest/UserGuide/IAM_Introduction.html\" target=\"_blank\">What Is IAM?</a>", "category": "security", "metadata": [] } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的 AWS Trusted Advisor

下列程式碼範例會示範如何使用refresh-trusted-advisor-check

AWS CLI

重新整理 AWS 信任的建議程式檢查

下列refresh-trusted-advisor-check範例會重新整理您 AWS 帳戶中的 Amazon S3 儲存貯體許可受 Trusted Advisor 檢查。

aws support refresh-trusted-advisor-check \ --check-id "Pfx0RwqBli"

輸出:

{ "status": { "checkId": "Pfx0RwqBli", "status": "enqueued", "millisUntilNextRefreshable": 3599992 } }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的 AWS Trusted Advisor

下列程式碼範例會示範如何使用resolve-case

AWS CLI

若要解決支援案例

下列resolve-case範例會解決您 AWS 帳戶中的支援案例。

aws support resolve-case \ --case-id "case-12345678910-2013-c4c1d2bf33c5cf47"

輸出:

{ "finalCaseStatus": "resolved", "initialCaseStatus": "work-in-progress" }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

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