本文件僅適用於 AWS CLI 的第 1 版。如需 AWS CLI 第 2 版的相關文件,請參閲第 2 版使用者指南。
故障診斷 AWS CLI 錯誤
本節介紹常見錯誤和解決問題時應遵循的故障診斷步驟。我們建議先遵循一般故障診斷。
內容
先嘗試的一般故障診斷
如果您收到錯誤或遇到 AWS CLI 的問題,我們建議您遵循以下一般建議以協助您進行故障診斷。
檢查您的 AWS CLI 命令格式
如果您收到錯誤,指出命令不存在,或無法辨識文件表示可用的參數,則您的命令格式可能不正確。我們建議您檢查以下內容:
-
檢查您的命令是否有拼寫和格式錯誤。
-
確認所有的引號和逸出適合您的終端機在您的命令中是正確的。
-
產生AWS CLI 骨架以確認您的命令結構。
-
如果您在終端處理 JSON 格式時遇到問題,我們建議透過使用 Blob 將 JSON 資料直接傳遞至 AWS CLI,以跳過終端機的引用規則。
如需有關如何建構特定命令的詳細資訊,請參閱AWS CLI 參考指南。
確認您執行的是最新版本的 AWS CLI
如果您收到錯誤,指出命令不存在,或者無法辨識AWS CLI 參考指南表示可用的參數,請首先確認您的命令格式是正確的。如果格式正確,我們建議您升級到最新版本的 AWS CLI。AWS CLI 的更新版本幾乎會在每個工作天發行。AWS CLI 的新版本推出了新的 AWS 服務、功能和參數。要存取這些新服務、功能或參數的唯一方法,就是升級到該元素首次推出之後所發行的版本。
更新 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 已配置
如果您的 config
和 credentials
檔案或您的 IAM 使用者或角色未正確配置。有關解決 config
和 credentials
檔案或您的 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 CLI 之後找不到
aws
命令,您可能需要重新啟動終端機才能辨識任何PATH
更新。 - 可能原因:AWS CLI 未完整安裝
-
範例錯誤文字:
$
aws --version
command not found: aws
如果在第一次安裝或更新 AWS CLI 之後找不到
aws
命令,可能是它並未完整安裝。請遵循 安裝、更新和解除安裝 AWS CLI 中適用於您平台的步驟,嘗試重新安裝。 - 可能原因:AWS CLI 沒有許可 (Linux)
-
在 Linux 上首次安裝或更新 AWS CLI 之後,如果找不到
aws
命令,可能是對安裝資料夾缺少execute
許可。請使用 AWS CLI 安裝的PATH
執行以下命令,對 AWS CLI 提供chmod
許可:$
sudo chmod -R 755
/usr/local/aws-cli/
- 可能原因:安裝期間作業系統的
PATH
未更新。 -
範例錯誤文字:
$
aws --version
command not found: aws
您可能需要將
aws
可執行檔新增到作業系統的PATH
環境變數中。若要將 AWS CLI 新增到您的PATH
,請使用以下適用於您作業系統的指示。
「aws --version
」命令傳回的版本與您安裝的版本不同
您的終端機可能會傳回與您預期不同的 AWS CLI 的 PATH
。
- 可能的原因:安裝後需要重新啟動終端機
-
如果
aws
命令顯示錯誤的版本,您可能需要重新啟動終端機才能辨識任何PATH
更新。 - 可能的原因:您有多個版本的 AWS CLI
-
如果您更新了 AWS CLI 並使用與已存在安裝不同的安裝方法,可能會導致安裝多個版本。例如,如果您在 Linux 或 macOS 上使用
pip
,但嘗試使用.pkg
安裝檔案,這可能會導致一些衝突,特別是如果您的PATH
指向舊版本。若要解決此問題,請解除安裝所有版本的 AWS CLI,並執行全新安裝。
解除安裝所有版本後,請遵循適用於您作業系統的指示,安裝所需版本的 AWS CLI 第 1 版或 AWS CLI 第 2 版。
注意 如果這種情況發生在安裝 AWS CLI 第 2 版,並且已有安裝 AWS CLI 第 1 版,請遵循從 AWS CLI 第 1 版遷移時的安裝指示中的遷移指示。
「aws --version
」命令在解除安裝 AWS CLI 後傳回一個版本
這通常發生在您的系統上仍有已安裝的 AWS CLI。
- 可能的原因:解除安裝後需要重新啟動終端機
-
如果
aws --version
命令仍可運作,您可能需要重新啟動終端機才能辨識任何終端機更新。 - 可能的原因:您的系統上有多個版本的 AWS CLI,或者沒有使用與最初安裝 AWS CLI 時相同的方法進行解除安裝
-
如果您使用不同於安裝它的方法來解除安裝 AWS CLI,或者如果您已安裝多個版本,AWS CLI 可能會無法正確解除安裝。例如,如果您目前的安裝使用
pip
,您就必須使用pip
將它解除安裝。若要解決此問題,請使用您當初安裝它的方法來解除安裝 AWS CLI。-
遵循適用於您作業系統的指示和原始的安裝方法,解除安裝 AWS CLI 第 1 版和 AWS CLI 第 2 版。
-
關閉所有已打開的終端機。
-
打開您的首選終端機,輸入以下命令並確認沒有傳回任何版本。
$
aws --version
command not found: aws
如果輸出中仍有列出版本,AWS CLI 很可能使用了不同的方法安裝,或者有多個版本。如果您不知道您當初安裝 AWS CLI 的方式,請遵循適用於您作業系統的 AWS CLI 第 1 版和 AWS CLI 第 2 版的各種解除安裝方法指示進行操作,直到未接收到版本輸出為止。
注意 如果您使用套件管理工具來安裝 AWS CLI (
pip
、apt
、brew
等),您就必須使用相同的套件管理工具來予以解除安裝。請務必遵循套件管理工具所提供有關如何解除所有版本安裝套件的指示。
-
存取遭拒錯誤
- 可能原因: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 操作。連接到該 IAM 使用者或角色的政策必須授予您許可,才能呼叫與您使用 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 讀取憑證的位置可能與您的預期不同,或您的金鑰對資訊不正確。您可以執行
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
若要確認您的金鑰對詳細資訊,請查看
config
和credentials
檔案。如需config
和credentials
檔案的詳細資訊,請參閱 組態與憑證檔案設定。如需詳細資訊,請參閱 存取金鑰 ID 和私密存取金鑰。 - 可能原因:電腦的時鐘不同步。
-
如果您使用的是有效憑證,則您的時鐘可能不同步。在 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 無法辨識的內容。
我們建議重新產生私密金鑰,以取得不包含導致問題的特殊字元的私密金鑰。
未找到 Windows 控制台錯誤
範例錯誤文字:
$
aws s3 ls
No Windows console found. Are you running cmd.exe?
在使用 AWS CLI 命令時,您收到「找不到 Windows 主控台。您正在執行 cmd.exe 嗎?」 錯誤訊息。如果您安裝的 Python prompt_toolkit
已過時,這通常是會在 AWS CLI 第 1 版看到的問題。若要解決這個問題,請安裝 Python 網站prompt_toolkit
版本。
SSL 憑證錯誤
- 可能原因:AWS CLI 不信任您的代理的憑證
-
範例錯誤文字:
$
aws s3 ls
[SSL: CERTIFICATE_ VERIFY_FAILED] certificate verify failed
當您使用 AWS CLI 命令時,您會收到
[SSL: CERTIFICATE_ VERIFY_FAILED] certificate verify failed
錯誤訊息。這是因為 AWS CLI 不信任 proxy 的憑證,而 proxy 的憑證正在進行自我簽署並且您的公司被設定為憑證授權機構 (CA) 等因素都可能造成這樣的錯誤。這可防止 AWS CLI 在本機 CA 登錄中找到您公司的 CA 根憑證。若要解決這個問題,請使用
ca_bundle
組態檔案設定、--ca-bundle 命令列選項或AWS_CA_BUNDLE
環境變數,指示 AWS CLI 可找到公司.pem
檔案的位置。 - 可能的原因:您的配置未指向正確的 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 CLI 問題的其他協助,請造訪 GitHub 上的 AWS CLI 社群