取得 AWS CLI 相關協助 - AWS Command Line Interface

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

取得 AWS CLI 相關協助

本主題說明如何存取 AWS Command Line Interface (AWS CLI) 的說明內容。

內建 AWS CLI 說明命令

使用 AWS Command Line Interface (AWS CLI) 時,您可以獲得任何命令的說明。若要這樣做,只需在命令名稱結尾輸入 help

例如,下列命令會顯示一般 AWS CLI 選項與可用之頂級命令的說明。

$ aws help

以下命令會顯示可用的 Amazon Elastic Compute Cloud (Amazon EC2) 特定命令。

$ aws ec2 help

以下範例會顯示 Amazon EC2 DescribeInstances 操作的詳細說明。說明包括輸入參數的描述、可用的篩選條件以及輸出包含的內容。此外也包含範例,顯示如何輸入命令的常見變化。

$ aws ec2 describe-instances help

各個命令的說明均分為六個區段:

名稱

命令的名稱。

NAME describe-instances -
描述

命令叫用之 API 操作的描述。

DESCRIPTION Describes one or more of your instances. If you specify one or more instance IDs, Amazon EC2 returns information for those instances. If you do not specify instance IDs, Amazon EC2 returns information for all relevant instances. If you specify an instance ID that is not valid, an error is returned. If you specify an instance that you do not own, it is not included in the returned results. ...
概要

使用命令和其選項的基本語法。如果有選項顯示在方括號內,代表為選用、具有預設值,或是具有可使用的替代選項。

SYNOPSIS describe-instances [--dry-run | --no-dry-run] [--instance-ids <value>] [--filters <value>] [--cli-input-json <value>] [--starting-token <value>] [--page-size <value>] [--max-items <value>] [--generate-cli-skeleton]

例如,describe-instances 具備預設行為,說明目前帳戶和 AWS 區域中的所有執行個體。您可選擇指定 dry-run 清單來描述一個或多個執行個體。instance-ids 是一個選用的布林值旗標,其不採用數值。若要使用布林值旗標,請指定顯示數值,在此範例中為 --dry-run--no-dry-run。同樣地,--generate-cli-skeleton 不採用數值。如果選項的使用具有條件,則這些條件會在 OPTIONS 區段中說明,或顯示在範例中。

選項

概要中顯示之各個選項的說明。

OPTIONS --dry-run | --no-dry-run (boolean) Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRun- Operation . Otherwise, it is UnauthorizedOperation . --instance-ids (list) One or more instance IDs. Default: Describes all your instances. ...
範例

命令使用及其選項的範例。如果您所需的命令或使用案例沒有範例,請使用本頁面的意見回饋連結要求提供範例,或在該命令說明頁面的 AWS CLI 命令參考中要求提供範例。

EXAMPLES To describe an Amazon EC2 instance Command: aws ec2 describe-instances --instance-ids i-5203422c To describe all instances with the instance type m1.small Command: aws ec2 describe-instances --filters "Name=instance-type,Values=m1.small" To describe all instances with an Owner tag Command: aws ec2 describe-instances --filters "Name=tag-key,Values=Owner" ...
輸出

來自 AWS 的回應中所包含各個欄位與資料類型的說明。

對於 describe-instances,輸出是保留物件的清單,每個清單都包含若干欄位和物件,而這些欄位和物件包含與其關聯之執行個體的資訊。此資訊來自 Amazon EC2 所使用的保留資料類型的 API 文件

OUTPUT Reservations -> (list) One or more reservations. (structure) Describes a reservation. ReservationId -> (string) The ID of the reservation. OwnerId -> (string) The ID of the AWS account that owns the reservation. RequesterId -> (string) The ID of the requester that launched the instances on your behalf (for example, AWS Management Console or Auto Scaling). Groups -> (list) One or more security groups. (structure) Describes a security group. GroupName -> (string) The name of the security group. GroupId -> (string) The ID of the security group. Instances -> (list) One or more instances. (structure) Describes an instance. InstanceId -> (string) The ID of the instance. ImageId -> (string) The ID of the AMI used to launch the instance. State -> (structure) The current state of the instance. Code -> (integer) The low byte represents the state. The high byte is an opaque internal value and should be ignored. ...

當 AWS CLI 轉譯以 JSON 格式輸出時,其就會變成一列保留物件,類似以下範例。

{ "Reservations": [ { "OwnerId": "012345678901", "ReservationId": "r-4c58f8a0", "Groups": [], "RequesterId": "012345678901", "Instances": [ { "Monitoring": { "State": "disabled" }, "PublicDnsName": "ec2-52-74-16-12.us-west-2.compute.amazonaws.com", "State": { "Code": 16, "Name": "running" }, ...

每個保留物件均包含說明該保留的欄位,以及執行個體物件列陣,每個執行個體物件都有提供說明的專屬欄位 (例如 PublicDnsName) 和物件 (例如 State)。

Windows 使用者

您可將說明命令的輸出輸送 (|) 到 more 命令,以便一次檢視一個說明檔案頁面。按下空格鍵或 PgDn 鍵檢視更多文件內容,按 q 鍵即可退出。

C:\> aws ec2 describe-instances help | more

AWS CLI 參考指南

說明檔案包含連結,無法從命令列檢視或瀏覽。您可以使用線上 AWS CLI 第 2 版參考指南來檢視這些連結並與其互動。參考也包含所有 AWS CLI 命令的說明內容。提供的說明可在行動裝置、平板電腦或桌上型電腦螢幕上輕鬆導覽和檢視。

API 文件

AWS CLI 中的所有命令均對應於針對 AWS 服務公有 API 所提出的請求。每個具備公有 API 的服務均有 API 參考,這些文件可以在 AWS 文件網站上該服務的首頁中找到。API 參考的內容根據 API 的建構方式和所用協議而有所差異。一般來說,API 參考包含詳細資訊,說明 API 支援的操作、傳送到服務或從服務傳送的資料,以及服務可能報告的任何錯誤情況。

API 文件區段
  • 動作 – 關於每個操作及其參數 (包含長度限制或內容限制以及預設值) 的詳細資訊。它會列出此操作可能發生的錯誤。每個操作對應至 AWS CLI 中的子命令。

  • 資料類型 – 結構的詳細資訊,命令可能需要這些結構作為參數,或傳回以回應請求。

  • 常用參數 – 服務的所有動作共用之參數的詳細資訊。

  • 常見錯誤 – 服務的任何操作可能傳回之錯誤的詳細資訊。

每個區段的名稱或可用性,會依據服務而有所差異。

服務特定的 CLI

某些服務具有單獨的 CLI,該 CLI 的建立日期早於建立單一 AWS CLI 以與所有服務搭配使用。這些服務特定的 CLI 具有個別專屬的文件,可以從該服務的文件頁面中連結取得。服務專屬 CLI 的文件不適用於 AWS CLI。

故障診斷錯誤

如需診斷和修復 AWS CLI 錯誤的協助,請參閱排解 AWS CLI 錯誤

其他協助

如需解決 AWS CLI 問題的其他協助,請造訪 GitHub 上的 AWS CLI 社群