排解 AWS CLI 錯誤 - AWS Command Line Interface

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

排解 AWS CLI 錯誤

本節介紹常見錯誤和解決問題時應遵循的故障診斷步驟。我們建議先遵循一般故障診斷

先嘗試的一般故障診斷

如果您收到錯誤或遇到問題 AWS CLI,我們建議您使用以下一般提示來協助您進行疑難排解。

回到頁首

檢查您的 AWS CLI 命令格式

如果您收到錯誤,指出命令不存在,或無法辨識文件表示可用的參數 (Parameter validation failed),則您的命令格式可能不正確。我們建議您檢查以下內容:

有關如何構建特定命令的更多信息,請參閱第 2 AWS CLI 版參考指南

回到頁首

檢查 AWS 區域 您的 AWS CLI 命令是否正在使用

注意

使用 AWS 區域 時,您必須明確指定 AWS CLI,或透過設定預設「區域」(Region) 來指定。如需可指定之所有項目 AWS 區域 的清單,請參閱中的AWS 區域和端點Amazon Web Services 一般參考。所使用的 AWS 區域 指示器與您在 AWS Management Console URL 和服務端點中看到的名稱相同。 AWS CLI

如果您指定的無法使用,或者您的資源位於不同的資源,則可能會發生錯誤 AWS 區域 或 AWS 服務 未預期的結果 AWS 區域。依優先順序排列, AWS 區域 會以下列方式設定:

確認您使用的是正確 AWS 區域 的資源。

回到頁首

確認您執行的是最新版本的 AWS CLI

如果您收到指令不存在的錯誤訊息,或無法辨識參考指南第 2 AWS CLI 版參所說的參數可用,請先確認您的命令格式正確。如果格式正確,我們建議您升級到最新版本的 AWS CLI。的更新版本幾乎每個工作日都 AWS CLI 會發布。新的 AWS 服務、功能和參數會在這些新版本的 AWS CLI. 要存取這些新服務、功能或參數的唯一方法,就是升級到該元素首次推出之後所發行的版本。

更新版本的方式取 AWS CLI 決於您最初的安裝方式,如中所述安裝或更新到最新版本的 AWS CLI

如果您使用其中一個隨附的安裝程式,您可能需要移除現有的安裝,然後下載並安裝適用於您作業系統的最新版本安裝程式。

回到頁首

設定 --debug 選項

當 AWS CLI 報告您無法立即理解的錯誤,或產生不預期的結果時,您可以使用該--debug選項再次執行命令,以取得有關錯誤的更多詳細資訊。使用此選項時, AWS CLI 會輸出有關處理命令所需的每個步驟的詳細資訊。輸出中的詳細資訊可協助您判斷錯誤發生在哪個步驟,以及可提供觸發錯誤的線索內容。

您可以將輸出傳送到文字檔案,以供日後檢閱,或在收到要求時將其傳送給 AWS Support 。

當您包含 --debug 選項時,所包括的部分詳細資訊為:

  • 正在尋找的憑證

  • 正在剖析所提供的參數

  • 構建發送到 AWS 服務器的請求

  • 傳送至的要求內容 AWS

  • 原始回應的內容

  • 格式化的輸出

以下是使用和不使用 --debug 選項執行命令的範例。

$ aws iam list-groups --profile MyTestProfile { "Groups": [ { "Path": "/", "GroupName": "MyTestGroup", "GroupId": "AGPA0123456789EXAMPLE", "Arn": "arn:aws:iam::123456789012:group/MyTestGroup", "CreateDate": "2019-08-12T19:34:04Z" } ] }
$ aws iam list-groups --profile MyTestProfile --debug 2019-08-12 12:36:18,305 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.16.215 Python/3.7.3 Linux/4.14.133-113.105.amzn2.x86_64 botocore/1.12.205 2019-08-12 12:36:18,305 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['iam', 'list-groups', '--debug'] 2019-08-12 12:36:18,305 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_scalar_parsers at 0x7fdf173161e0> 2019-08-12 12:36:18,305 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function register_uri_param_handler at 0x7fdf17dec400> 2019-08-12 12:36:18,305 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x7fdf17da9378> 2019-08-12 12:36:18,307 - MainThread - botocore.credentials - DEBUG - Skipping environment variable credential check because profile name was explicitly set. 2019-08-12 12:36:18,307 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function attach_history_handler at 0x7fdf173ed9d8> 2019-08-12 12:36:18,308 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /home/ec2-user/venv/lib/python3.7/site-packages/botocore/data/iam/2010-05-08/service-2.json 2019-08-12 12:36:18,317 - MainThread - botocore.hooks - DEBUG - Event building-command-table.iam: calling handler <function add_waiters at 0x7fdf1731a840> 2019-08-12 12:36:18,320 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /home/ec2-user/venv/lib/python3.7/site-packages/botocore/data/iam/2010-05-08/waiters-2.json 2019-08-12 12:36:18,321 - MainThread - awscli.clidriver - DEBUG - OrderedDict([('path-prefix', <awscli.arguments.CLIArgument object at 0x7fdf171ac780>), ('marker', <awscli.arguments.CLIArgument object at 0x7fdf171b09e8>), ('max-items', <awscli.arguments.CLIArgument object at 0x7fdf171b09b0>)]) 2019-08-12 12:36:18,322 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.iam.list-groups: calling handler <function add_streaming_output_arg at 0x7fdf17316510> 2019-08-12 12:36:18,322 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.iam.list-groups: calling handler <function add_cli_input_json at 0x7fdf17da9d90> 2019-08-12 12:36:18,322 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.iam.list-groups: calling handler <function unify_paging_params at 0x7fdf17328048> 2019-08-12 12:36:18,326 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /home/ec2-user/venv/lib/python3.7/site-packages/botocore/data/iam/2010-05-08/paginators-1.json 2019-08-12 12:36:18,326 - MainThread - awscli.customizations.paginate - DEBUG - Modifying paging parameters for operation: ListGroups 2019-08-12 12:36:18,326 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.iam.list-groups: calling handler <function add_generate_skeleton at 0x7fdf1737eae8> 2019-08-12 12:36:18,326 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.iam.list-groups: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7fdf171b0a58>> 2019-08-12 12:36:18,327 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.iam.list-groups: calling handler <bound method GenerateCliSkeletonArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7fdf171c5978>> 2019-08-12 12:36:18,327 - MainThread - botocore.hooks - DEBUG - Event operation-args-parsed.iam.list-groups: calling handler functools.partial(<function check_should_enable_pagination at 0x7fdf17328158>, ['marker', 'max-items'], {'max-items': <awscli.arguments.CLIArgument object at 0x7fdf171b09b0>}, OrderedDict([('path-prefix', <awscli.arguments.CLIArgument object at 0x7fdf171ac780>), ('marker', <awscli.arguments.CLIArgument object at 0x7fdf171b09e8>), ('max-items', <awscli.customizations.paginate.PageArgument object at 0x7fdf171c58d0>), ('cli-input-json', <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7fdf171b0a58>), ('starting-token', <awscli.customizations.paginate.PageArgument object at 0x7fdf171b0a20>), ('page-size', <awscli.customizations.paginate.PageArgument object at 0x7fdf171c5828>), ('generate-cli-skeleton', <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7fdf171c5978>)])) 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.path-prefix: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.marker: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.max-items: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.cli-input-json: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.starting-token: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.page-size: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,328 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.iam.list-groups.generate-cli-skeleton: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fdf1725c978> 2019-08-12 12:36:18,329 - MainThread - botocore.hooks - DEBUG - Event calling-command.iam.list-groups: calling handler <bound method CliInputJSONArgument.add_to_call_parameters of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7fdf171b0a58>> 2019-08-12 12:36:18,329 - MainThread - botocore.hooks - DEBUG - Event calling-command.iam.list-groups: calling handler <bound method GenerateCliSkeletonArgument.generate_json_skeleton of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7fdf171c5978>> 2019-08-12 12:36:18,329 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role 2019-08-12 12:36:18,329 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity 2019-08-12 12:36:18,329 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file 2019-08-12 12:36:18,329 - MainThread - botocore.credentials - INFO - Found credentials in shared credentials file: ~/.aws/credentials 2019-08-12 12:36:18,330 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /home/ec2-user/venv/lib/python3.7/site-packages/botocore/data/endpoints.json 2019-08-12 12:36:18,334 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x7fdf1898eb70> 2019-08-12 12:36:18,337 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.iam: calling handler <function add_generate_presigned_url at 0x7fdf18a028c8> 2019-08-12 12:36:18,337 - MainThread - botocore.regions - DEBUG - Using partition endpoint for iam, us-west-2: aws-global 2019-08-12 12:36:18,337 - MainThread - botocore.args - DEBUG - The s3 config key is not a dictionary type, ignoring its value of: None 2019-08-12 12:36:18,340 - MainThread - botocore.endpoint - DEBUG - Setting iam timeout as (60, 60) 2019-08-12 12:36:18,341 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /home/ec2-user/venv/lib/python3.7/site-packages/botocore/data/_retry.json 2019-08-12 12:36:18,341 - MainThread - botocore.client - DEBUG - Registering retry handlers for service: iam 2019-08-12 12:36:18,342 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.iam.ListGroups: calling handler <function generate_idempotent_uuid at 0x7fdf189b10d0> 2019-08-12 12:36:18,342 - MainThread - botocore.hooks - DEBUG - Event before-call.iam.ListGroups: calling handler <function inject_api_version_header_if_needed at 0x7fdf189b2a60> 2019-08-12 12:36:18,343 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=ListGroups) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': 'aws-cli/1.16.215 Python/3.7.3 Linux/4.14.133-113.105.amzn2.x86_64 botocore/1.12.205'}, 'body': {'Action': 'ListGroups', 'Version': '2010-05-08'}, 'url': 'https://iam.amazonaws.com/', 'context': {'client_region': 'aws-global', 'client_config': <botocore.config.Config object at 0x7fdf16e9a4a8>, 'has_streaming_input': False, 'auth_type': None}} 2019-08-12 12:36:18,343 - MainThread - botocore.hooks - DEBUG - Event request-created.iam.ListGroups: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7fdf16e9a470>> 2019-08-12 12:36:18,343 - MainThread - botocore.hooks - DEBUG - Event choose-signer.iam.ListGroups: calling handler <function set_operation_specific_signer at 0x7fdf18996f28> 2019-08-12 12:36:18,343 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth. 2019-08-12 12:36:18,343 - MainThread - botocore.auth - DEBUG - CanonicalRequest: POST / content-type:application/x-www-form-urlencoded; charset=utf-8 host:iam.amazonaws.com x-amz-date:20190812T193618Z content-type;host;x-amz-date 5f776d91EXAMPLE9b8cb5eb5d6d4a787a33ae41c8cd6eEXAMPLEca69080e1e1f 2019-08-12 12:36:18,344 - MainThread - botocore.auth - DEBUG - StringToSign: AWS4-HMAC-SHA256 20190812T193618Z 20190812/us-east-1/iam/aws4_request ab7e367eEXAMPLE2769f178ea509978cf8bfa054874b3EXAMPLE8d043fab6cc9 2019-08-12 12:36:18,344 - MainThread - botocore.auth - DEBUG - Signature: d85a0EXAMPLEb40164f2f539cdc76d4f294fe822EXAMPLE18ad1ddf58a1a3ce7 2019-08-12 12:36:18,344 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://iam.amazonaws.com/, headers={'Content-Type': b'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': b'aws-cli/1.16.215 Python/3.7.3 Linux/4.14.133-113.105.amzn2.x86_64 botocore/1.12.205', 'X-Amz-Date': b'20190812T193618Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=AKIA01234567890EXAMPLE-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=d85a07692aceb401EXAMPLEa1b18ad1ddf58a1a3ce7EXAMPLE', 'Content-Length': '36'}> 2019-08-12 12:36:18,344 - MainThread - urllib3.util.retry - DEBUG - Converted retries value: False -> Retry(total=False, connect=None, read=None, redirect=0, status=None) 2019-08-12 12:36:18,344 - MainThread - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): iam.amazonaws.com:443 2019-08-12 12:36:18,664 - MainThread - urllib3.connectionpool - DEBUG - https://iam.amazonaws.com:443 "POST / HTTP/1.1" 200 570 2019-08-12 12:36:18,664 - MainThread - botocore.parsers - DEBUG - Response headers: {'x-amzn-RequestId': '74c11606-bd38-11e9-9c82-559da0adb349', 'Content-Type': 'text/xml', 'Content-Length': '570', 'Date': 'Mon, 12 Aug 2019 19:36:18 GMT'} 2019-08-12 12:36:18,664 - MainThread - botocore.parsers - DEBUG - Response body: b'<ListGroupsResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">\n <ListGroupsResult>\n <IsTruncated>false</IsTruncated>\n <Groups>\n <member>\n <Path>/</Path>\n <GroupName>MyTestGroup</GroupName>\n <Arn>arn:aws:iam::123456789012:group/MyTestGroup</Arn>\n <GroupId>AGPA1234567890EXAMPLE</GroupId>\n <CreateDate>2019-08-12T19:34:04Z</CreateDate>\n </member>\n </Groups>\n </ListGroupsResult>\n <ResponseMetadata>\n <RequestId>74c11606-bd38-11e9-9c82-559da0adb349</RequestId>\n </ResponseMetadata>\n</ListGroupsResponse>\n' 2019-08-12 12:36:18,665 - MainThread - botocore.hooks - DEBUG - Event needs-retry.iam.ListGroups: calling handler <botocore.retryhandler.RetryHandler object at 0x7fdf16e9a780> 2019-08-12 12:36:18,665 - MainThread - botocore.retryhandler - DEBUG - No retry needed. 2019-08-12 12:36:18,665 - MainThread - botocore.hooks - DEBUG - Event after-call.iam.ListGroups: calling handler <function json_decode_policies at 0x7fdf189b1d90> { "Groups": [ { "Path": "/", "GroupName": "MyTestGroup", "GroupId": "AGPA123456789012EXAMPLE", "Arn": "arn:aws:iam::123456789012:group/MyTestGroup", "CreateDate": "2019-08-12T19:34:04Z" } ] }

回到頁首

啟用並檢閱指 AWS CLI 令歷程記錄

您可以使用cli_history檔案設定來啟用 AWS CLI 指令歷程記錄。啟用此設定後,會記 AWS CLI 錄aws指令的歷史記錄。

您可以使用 aws history list 命令來列出歷史記錄,並且在 aws history show 命令中使用產生的 command_ids 取得詳細資訊。如需詳細資訊,請參閱 AWS CLI 參考指南中的 aws history

當您包含 --debug 選項時,所包括的部分詳細資訊為:

  • 對 botocore 執行的 API 呼叫

  • 狀態碼

  • HTTP 回應

  • 標頭

  • 傳回碼

您可以使用此資訊來確認參數資料和 API 呼叫以您預期的方式運作,然後推斷出您的命令在過程中的哪個步驟失敗。

回到頁首

確認您 AWS CLI 已設定

如果您的 configcredentials 檔案或您的 IAM 使用者或角色未正確配置,可能會出現各種錯誤。有關解決 configcredentials 檔案或您的 IAM 使用者或角色等錯誤的詳細資訊,請參閱 存取遭拒錯誤無效的憑證和金鑰錯誤

回到頁首

命令未找到錯誤

此錯誤意味著操作系統找不到 AWS CLI 命令。安裝可能不完整或需要更新。

可能的原因:您嘗試使用比安裝版本更新的 AWS CLI 功能,或格式不正確

範例錯誤文字:

$ aws s3 copy usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters] To see help text, you can run: aws help aws <command> help aws <command> <subcommand> help aws: error: argument subcommand: Invalid choice, valid choices are: ls | website cp | mv ....

如果您的命令格式不正確,或者您使用的是該功能發佈之前的早期版本,則可能會出現各種錯誤。若要解決圍繞這兩個問題的錯誤的詳細資訊,請參閱檢查您的 AWS CLI 命令格式確認您執行的是最新版本的 AWS CLI

回到頁首

可能的原因:安裝後需要重新啟動終端機

範例錯誤文字:

$ aws --version command not found: aws

如果在第一次安裝或更新之後找不到aws指令 AWS CLI,您可能需要重新啟動終端機,才能辨識任何PATH更新。

回到頁首

可能的原因: AWS CLI 未完全安裝

範例錯誤文字:

$ aws --version command not found: aws

如果在第一次安裝或更新之後找不到該aws命令 AWS CLI,它可能尚未完全安裝。請遵循 安裝或更新到最新版本的 AWS CLI 中適用於您平台的步驟,嘗試重新安裝。

回到頁首

可能的原因: AWS CLI 沒有權限(Linux)

如果在 Linux AWS CLI 上第一次安裝或更新之後找不到該aws命令,它可能沒有安裝在其中的資料夾的execute權限。使用您的 AWS CLI 安裝執行下列命令,以提供chmod權限給 AWS CLI:PATH

$ sudo chmod -R 755 /usr/local/aws-cli/

回到頁首

可能原因:安裝期間作業系統的 PATH 未更新。

範例錯誤文字:

$ aws --version command not found: aws

您可能需要將 aws 可執行檔新增到作業系統的 PATH 環境變數中。若要新增 AWS CLI 至您的PATH,請針對您的作業系統使用下列指示。

Linux and macOS
  1. 在您的使用者目錄中尋找 Shell 的描述檔命令碼。如果您不確定您擁有哪個 Shell,請執行 echo $SHELL

    $ ls -a ~ . .. .bash_logout .bash_profile .bashrc Desktop Documents Downloads
    • Bash.bash_profile.profile.bash_login

    • Zsh.zshrc

    • Tcsh.tcshrc.cshrc.login

  2. 將匯出命令新增至您的描述檔指令碼。以下命令將您的本地 bin 新增至目前的 PATH 變數。

    export PATH=/usr/local/bin:$PATH
  3. 將更新過的設定檔載入到您目前的工作階段。

    $ source ~/.bash_profile
Windows
  1. 在 Windows 命令提示符下,使用 where 命令與 /R path 參數來尋找 aws 檔案位置。結果將傳回所有包含 aws 的資料夾。

    C:\> where /R c:\ aws c:\Program Files\Amazon\AWSCLIV2\aws.exe ...

    根據預設, AWS CLI 版本 2 位於:

    c:\Program Files\Amazon\AWSCLIV2\aws.exe
  2. 按下 Windows 鍵並輸入 environment variables

  3. 從建議清單中,選擇Edit environment variables for your account (編輯您帳戶的環境變數)

  4. 選擇 PATH,然後選擇 Edit (編輯)

  5. 將您在第一個步驟中找到的路徑新增至Variable value (變數值)欄位中,例如 C:\Program Files\Amazon\AWSCLIV2\aws.exe

  6. 選擇 OK (確定) 兩次以套用新的設定。

  7. 關閉任何正在執行的命令提示,並重新開啟命令提示字元視窗。

回到頁首

aws --version」命令傳回的版本與您安裝的版本不同

您的終端機可能會返回與您預期的不同PATH。 AWS CLI

可能的原因:安裝後需要重新啟動終端機

如果 aws 命令顯示錯誤的版本,您可能需要重新啟動終端機才能辨識任何 PATH 更新。所有開放終端機都需要被關閉,不僅是您正在使用的終端機而已。

回到頁首

可能的原因:安裝後需要重新啟動系統

如果 aws 命令顯示錯誤的版本,且終端機重新啟動無效,您可能需要為其重新啟動系統以辨識您的 PATH 更新。

回到頁首

可能的原因:您有多個版本 AWS CLI

如果您更新 AWS CLI 並使用了與預先存在的安裝不同的安裝方法,則可能會導致安裝多個版本。例如,如果您在 Linux 或 macOS 上使用 pip,但嘗試使用 .pkg 安裝檔案,這可能會導致一些衝突,特別是如果您的 PATH 指向舊版本。

若要解決此問題,請解除安裝所有版本的 AWS CLI,並執行全新安裝。

解除安裝所有版本後,請遵循適用於您作業系統的指示,安裝所需版本的 AWS CLI 第 1 版AWS CLI 第 2 版

注意

如果在您使用預先安裝的版本 1 安裝 AWS CLI 版本 2 之後發生這種情況,請在轉指示。AWS CLI 第 2 版遷移指示

回到頁首

在解除安裝 aws --version「」之後,"" 指令會傳回一個版本 AWS CLI

這通常發生在系統上的某個位置仍然 AWS CLI 安裝時。

可能的原因:解除安裝後需要重新啟動終端機

如果 aws --version 命令仍可運作,您可能需要重新啟動終端機才能辨識任何終端機更新。

回到頁首

可能的原因:您的系統 AWS CLI 上有多個版本,或者沒有使用原來安裝的相同解除安裝方法 AWS CLI

如果您 AWS CLI 使用與安裝方式不同的方法解除安裝,或者您安裝了多個版本,則可 AWS CLI 能無法正確解除安裝。例如,如果您目前的安裝使用 pip,您就必須使用 pip 將它解除安裝。若要解決此問題,請 AWS CLI 使用您用來安裝它的相同方法解除安裝。

  1. 遵循適用於您作業系統的指示和原始的安裝方法,解除安裝 AWS CLI 第 1 版AWS CLI 第 2 版

  2. 關閉所有已打開的終端機。

  3. 打開您的首選終端機,輸入以下命令並確認沒有傳回任何版本。

    $ aws --version command not found: aws

    如果輸出中仍有列出的版本,則最有可能使用不同的方法進行安裝,或者有多個版本。 AWS CLI 如果您不知道安裝了哪種方法 AWS CLI,請遵循適用於您作業系統之AWS CLI 版本 1 和AWS CLI 版本 2 的每個解除安裝方法的指示,直到沒有收到版本輸出為止。

    注意

    如果您使用套件管理工具來安裝 AWS CLI (pipaptbrew 等),您就必須使用相同的套件管理工具來予以解除安裝。請務必遵循套件管理工具所提供有關如何解除所有版本安裝套件的指示。

回到頁首

AWS CLI 處理了具有不完整參數名稱的命令

可能的原因:您使用了 AWS CLI 參數的可辨識縮寫

由於 AWS CLI 是使用 Python 構建的,因此 AWS CLI 使用 Python argparse 庫,包括allow_abbrev參數。參數的縮寫由識別 AWS CLI 並加以處理。

下列命令範例會變更 CloudFormation 堆疊名稱。該參數--change-set-n被識別為的縮寫--change-set-name,並 AWS CLI 處理命令。

$ aws cloudformation create-change-set --stack-name my-stack --change-set-n my-change-set

當縮寫可能是多個命令時,參數將不會識別為縮寫。

下列命令範例會變更 CloudFormation 堆疊名稱。參數 --change-set- 不能以縮寫被識別,因為有可能是多個參數的縮寫,例如 --change-set-name--change-set-type。因此, AWS CLI 會處理該命令。

$ aws cloudformation create-change-set --stack-name my-stack --change-set- my-change-set
警告

請勿特意使用參數縮寫。它們不可靠,不具向後相容性。如果將任何新參數加入混淆縮寫的命令,它將會中斷您的命令。

此外,如果參數是單值引數,可能會造成您的命令出現非預期的行為。如果傳遞單值引數的多個執行個體,只會執行最後一個執行個體。在下列範例中,參數 --filters 是單值引數。已指定參數 --filters--filter--filter 參數是 --filters 的縮寫。這會導致應用 --filters 的兩個實例,並且只應用最後一個 --filter 參數。

$ aws ec2 describe-vpc-peering-connections \ --filters Name=tag:TagName,Values=VpcPeeringConnection \ --filter Name=status-code,Values=active

執行命令之前,請確認您使用的是有效的參數,以防止未預期的行為。

回到頁首

存取遭拒錯誤

可能的原因: AWS CLI 程序文件沒有「運行」權限

在 Linux 或 macOS 上,確定 aws 程式具有呼叫端使用者的執行許可。一般而言,許可會設定為 755

若要為您的使用者新增執行許可,請執行下列命令,並以電腦上的程式路徑取代 ~/.local/bin/aws 路徑。

$ chmod +x ~/.local/bin/aws

回到頁首

可能原因:您的 IAM 身分沒有執行此操作的許可

範例錯誤文字:

$ aws s3 ls An error occurred (AcessDenied) when calling the ListBuckets operation: Access denied.

當您執行 AWS CLI 命令時,系統會使用將您與 IAM 帳戶或角色建立關聯的登入資料代表您執行 AWS 作業。連接的政策必須授予您許可,才能呼叫與您使用 AWS CLI執行之命令相對應的 API 動作。

大部分的命令均呼叫單一個名稱與命令名稱相符的動作。但是如 aws s3 sync 的自訂命令會呼叫多個 API。您可以利用 --debug 選項來查看命令呼叫了哪一些 API。

如果您確定使用者或角色具有由原則指派的適當權限,請確定您的 AWS CLI 命令使用預期的認證。請參閱下一節有關認證的資料,以確認所使用的認證 AWS CLI 是否符合您預期的認證。

如需指派 IAM 許可的相關資訊,請參閱《IAM 使用者指南》中的存取管理概觀:許可和政策

回到頁首

無效的憑證和金鑰錯誤

範例錯誤文字:

$ aws s3 ls An error occurred (InvalidAccessKeyId) when calling the ListBuckets operation: The AWS Access Key Id you provided does not exist in our records.
$ aws s3 ls An error occurred (InvalidClientTokenId) when calling the ListBuckets operation: The security token included in the request is invalid.
可能的 AWS CLI 原因:讀取不正確的認證或從非預期的位置

AWS CLI 可能正在從您預期的不同位置讀取憑證,或者您的 key pair 資訊不正確。您可以執行 aws configure list 以確認使用哪些憑證。

以下範例說明如何檢查用於預設描述檔的憑證。

$ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************XYVA shared-credentials-file secret_key ****************ZAGY shared-credentials-file region us-west-2 config-file ~/.aws/config

以下範例說明如何檢查具名描述檔的憑證。

$ aws configure list --profile saanvi Name Value Type Location ---- ----- ---- -------- profile saanvi manual --profile access_key **************** shared-credentials-file secret_key **************** shared-credentials-file region us-west-2 config-file ~/.aws/config

若要確認您的金鑰對詳細資訊,請查看 configcredentials 檔案。如需 configcredentials 檔案的詳細資訊,請參閱 組態與憑證檔案設定。如需深入了解憑證與身分驗證,包含憑證優先順序,請參閱 驗證與存取憑證

回到頁首

可能原因:電腦的時鐘不同步。

如果您使用的是有效憑證,則您的時鐘可能不同步。在 Linux 或 macOS 上,執行 date 來檢查時間。

$ date

如果您的系統時鐘誤差在幾分鐘內,則請使用 ntpd 來進行同步。

$ sudo service ntpd stop $ sudo ntpdate time.nist.gov $ sudo service ntpd start $ ntpstat

在 Windows 上,使用控制台的日期與時間選項來設定系統時鐘。

回到頁首

簽章不相符錯誤

範例錯誤文字:

$ aws s3 ls An error occurred (SignatureDoesNotMatch) when calling the ListBuckets operation: The request signature we calculated does not match the signature you provided. Check your key and signing method.

AWS CLI 運行命令時,它會向服務 AWS 器發送加密請求以執行適當的 AWS 服務操作。您的憑據(訪問密鑰和密鑰)涉及加密,並允許 AWS 對發出請求的人進行身份驗證。有幾種情況可能會干擾此程序的正確操作,如下所述。

可能的原因:您的時鐘與 AWS 伺服器不同步

為了協助防止重送攻擊,可以在加密/解密程序期間使用目前時間。如果用戶端和伺服器的時間差異超過允許的數量,程序可能會失敗並拒絕請求。當您在時鐘與主機時鐘不同步的虛擬機器中執行命令,也可能發生這種情況。其中一個可能的原因是虛擬機器休眠,在喚醒後需要一些時間才能與主機的時鐘同步。

在 Linux 或 macOS 上,執行 date 來檢查時間。

$ date

如果您的系統時鐘誤差在幾分鐘內,則請使用 ntpd 來進行同步。

$ sudo service ntpd stop $ sudo ntpdate time.nist.gov $ sudo service ntpd start $ ntpstat

在 Windows 上,使用控制台的日期與時間選項來設定系統時鐘。

回到頁首

可能的原因:您的作業系統處理包含特定特殊字元的 AWS 金鑰不當

如果您的 AWS 金鑰包含某些特殊字元,例如-+/、或%,某些作業系統變體會不正確處理字串,並導致金鑰字串解譯不正確。

如果您使用其他工具或指令碼來處理金鑰,例如在新執行個體上建立認證檔案的工具,這些工具和指令碼可能會自行處理特殊字元,導致這些字元轉換為 AWS 無法再辨識的項目。

我們建議重新產生私密金鑰,以取得不包含導致問題的特殊字元的私密金鑰。

回到頁首

SSL 憑證錯誤

可能的原因: AWS CLI 不信任您的代理證書

範例錯誤文字:

$ aws s3 ls [SSL: CERTIFICATE_ VERIFY_FAILED] certificate verify failed

當您使用指 AWS CLI 令時,您會收到錯[SSL: CERTIFICATE_ VERIFY_FAILED] certificate verify failed誤訊息。這是因為您的 Proxy 憑證已自行簽署、您的公司設定為憑證授權單位 (CA) 等因素,因此 AWS CLI 不信任 Proxy 的憑證所致。這可防 AWS CLI 止在本機 CA 登錄中尋找您公司的 CA 根憑證。

若要修正此問題,請使用ca_bundle組態.pem檔設定、--ca-bundle命令列選項或AWS_CA_BUNDLE環境變數,指示 AWS CLI 在何處尋找您的公司檔案。

回到頁首

可能的原因:您的配置未指向正確的 CA 根憑證位置

範例錯誤文字:

$ aws s3 ls SSL validation failed for regionname [Errno 2] No such file or directory

這是由於您的憑證授權機構 (CA) 套件檔案位置在 AWS CLI中被錯誤設定。若要解決這個問題,請確認您公司 .pem 檔案的位置,然後使用 ca_bundle 組態檔案設定、--ca-bundle 命令列選項或 AWS_CA_BUNDLE 環境變數,更新 AWS CLI 組態。

回到頁首

可能的原因:您的配置使用不正確 AWS 區域

範例錯誤文字:

$ aws s3 ls [SSL: CERTIFICATE_ VERIFY_FAILED] certificate verify failed

如果您指定的無法使用,或者您的資源位於不同的資源,則可能會發生錯誤 AWS 區域 或 AWS 服務 未預期的結果 AWS 區域。如需疑難排解步驟,請參閱檢查 AWS 區域 您的 AWS CLI 命令是否正在使用

回到頁首

可能的原因:您的 TLS 版本需要更新

範例錯誤文字:

$ aws s3 ls [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled

使 AWS 服務 用的 TLS 版本與您裝置的 TLS 版本不相容。若要解決此問題,請更新至支援的 TLS 版本。如需詳細資訊,請參閱 強制執行 TLS 的最低版本

回到頁首

JSON 無效錯誤

範例錯誤文字:

$ aws dynamodb update-table \ --provisioned-throughput '{"ReadCapacityUnits":15,WriteCapacityUnits":10}' \ --table-name MyDDBTable Error parsing parameter '--provisioned-throughput': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 25 (char 24) JSON received: {"ReadCapacityUnits":15,WriteCapacityUnits":10}

當您使用 AWS CLI 指令時,您會收到 "Invalid JSON" 錯誤訊息。這通常是當您輸入具有預期 JSON 格式的命令並且 AWS CLI 無法正確讀取 JSON 時看到的錯誤。

可能的原因:您沒有輸入 AWS CLI 要使用的有效 JSON

請確定您已為命令輸入有效的 JSON。我們建議您為有格式化問題的 JSON 使用 JSON 驗證器。

若要在命令列中使用更進階的 JSON,請考慮使用 jq 之類的命令列 JSON 處理器來建立 JSON 字串。如需有關的詳細資訊jq,請參閱上的 jq 儲存庫GitHub

回到頁首

可能的原因:終端機的引用規則阻止將有效的 JSON 發送到 AWS CLI

在 AWS CLI 接收來自命令的任何內容之前,您的終端使用它自己的引用和轉義規則處理該命令。由於終端機的格式化規則,您的部分 JSON 內容可能在命令傳遞至 AWS CLI之前遭除去。格式化命令時,務必使用終端機的引號規則

若要進行疑難排解,請使用 echo 命令查看 shell 如何處理您的參數:

$ echo {"ReadCapacityUnits":15,"WriteCapacityUnits":10} ReadCapacityUnits:15 WriteCapacityUnits:10
$ echo '{"ReadCapacityUnits":15,"WriteCapacityUnits":10}' {"ReadCapacityUnits":15,"WriteCapacityUnits":10}

修改您的命令,直到傳回有效的 JSON 為止。

如需深入疑難排解的詳細資訊,請使用 --debug 參數查看偵錯日誌,日誌將準確顯示傳遞至 AWS CLI的內容:

$ aws dynamodb update-table \ --provisioned-throughput '{"ReadCapacityUnits":15,WriteCapacityUnits":10}' \ --table-name MyDDBTable \ --debug 2022-07-19 22:25:07,741 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.18.147 Python/2.7.18 Linux/5.4.196-119.356.amzn2int.x86_64 botocore/1.18.6 2022-07-19 22:25:07,741 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['dynamodb', 'update-table', '--provisioned-throughput', '{"ReadCapacityUnits":15,WriteCapacityUnits":10}', '--table-name', 'MyDDBTable', '--debug']

請用終端機的引號規則修正 JSON 輸入在傳送至 AWS CLI時可能發生的任何問題。如需引號規則的詳細資訊,請參閱搭配 AWS CLI 中的字串使用引號

注意

如果您在取得有效 JSON 時遇到問題 AWS CLI,我們建議您使用 Blob 將 JSON 資料直接傳遞至. AWS CLI如需 Blobs 的詳細資訊,請參閱 Blob

回到頁首

其他資源

如需有關您 AWS CLI 問題的其他協助,請造訪上的AWS CLI 社GitHubAWS re:Post 社群

回到頁首