使用 AWS CLI 的 支援 範例 - AWS Command Line Interface

使用 AWS CLI 的 支援 範例

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 支援 來執行動作,並實作常見案例。

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

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

主題

動作

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

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

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

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

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

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

  • 如需 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" } }

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

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

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

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

  • 如需 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==" }

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

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

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

  • 如需 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" } ] }

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

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

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

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

AWS CLI

列出 AWS Trusted Advisor 檢查的結果

下列 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 } ] } }

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

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

AWS CLI

列出 AWS Trusted Advisor 檢查的摘要

下列 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 } } } ] }

如需詳細資訊,請參閱《AWS Support 使用者指南》中的 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": [] } ] }

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

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

AWS CLI

重新整理 AWS Trusted Advisor 檢查

下列 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 } }

如需詳細資訊,請參閱《AWS Support 使用者指南》中的 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" }

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

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