Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3api head-object does not return proper error for unknown key #666

Closed
quiver opened this issue Feb 22, 2014 · 3 comments
Closed

s3api head-object does not return proper error for unknown key #666

quiver opened this issue Feb 22, 2014 · 3 comments
Labels
feature-request A feature should be added or improved. s3

Comments

@quiver
Copy link
Contributor

quiver commented Feb 22, 2014

This may not be an issue of aws-cli per se, but rather an issue of s3 api in general.

When you execute s3api head-object for unknown key, aws command just returns client error (Unknown), which makes it difficult to track down the problem.
s3 server returns 404 http status for HEAD, but response body is empty.

For comparison, s3api get-object-acl returns A client error (NoSuchKey) for such case and error message is included in xml formatted response body..

Demonstration(removing unrelated parts)

$ aws s3api head-object --bucket my-bucket-name --key unknwon-key  --debug
...
2014-02-22 14:16:49,204 - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "HEAD /data/std.pn HTTP/1.1" 404 0
2014-02-22 14:16:49,205 - botocore.response - DEBUG - Response Headers:
x-amz-id-2: cbPyjTjNGQ0bXHi54ZtkarD9yd2mLFsXZT1afXtlxcVtXpwIbqdhynigPOr+LTnS
server: AmazonS3
transfer-encoding: chunked
x-amz-request-id: E965558DECC7D101
date: Sat, 22 Feb 2014 05:16:25 GMT
content-type: application/xml
2014-02-22 14:16:49,206 - botocore.response - DEBUG - Response Body:

...
2014-02-22 14:16:49,207 - awscli.errorhandler - DEBUG - HTTP Response Code: 404
...
2014-02-22 14:16:49,209 - awscli.clidriver - DEBUG - Exiting with rc 255
A client error (Unknown) occurred when calling the HeadObject operation: Unknown
@messick
Copy link

messick commented May 15, 2014

The same useless error happens when the user does not have access to the key in question:

2014-05-15 08:56:32,745 - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "HEAD /whatever.txt HTTP/1.1" 403 0
2014-05-15 08:56:32,746 - botocore.response - DEBUG - Response Headers:
x-amz-id-2: WSuW9Awdc8KiwdoysbWY+3ciyRzdLr543nW1K/pnc1auI27OpOiPC6lLGvUleNB8wofHWHWHrY4=
server: AmazonS3
transfer-encoding: chunked
x-amz-request-id: 6A5B416D7DEC96E7
date: Thu, 15 May 2014 15:56:31 GMT
content-type: application/xml
2014-05-15 08:56:32,746 - botocore.response - DEBUG - Response Body:

2014-05-15 08:56:32,746 - botocore.hooks - DEBUG - Event needs-retry.s3.HeadObject: calling handler <botocore.retryhandler.RetryHandler object at 0x1cb7910>
2014-05-15 08:56:32,746 - botocore.retryhandler - DEBUG - No retry needed.
2014-05-15 08:56:32,747 - botocore.hooks - DEBUG - Event after-call.s3.HeadObject: calling handler <awscli.errorhandler.ErrorHandler object at 0x7fec19b42e50>
2014-05-15 08:56:32,747 - awscli.errorhandler - DEBUG - HTTP Response Code: 403
2014-05-15 08:56:32,747 - awscli.clidriver - DEBUG - Exception caught in main()
....
ClientError: A client error (Unknown) occurred when calling the HeadObject operation: Unknown
2014-05-15 08:56:32,748 - awscli.clidriver - DEBUG - Exiting with rc 255

@jamesls
Copy link
Member

jamesls commented Jan 14, 2015

This is fixed now in the latest version of the CLI (looks like we forgot to link the fix with this issue):

$ aws s3api head-object --bucket mybucket --key bar.txt

A client error (404) occurred when calling the HeadObject operation: Not Found

The issue here is that this is a HEAD request, which does not contain a response body. In these scenarios we just use the status code message as the error message as shown above.

@jamesls jamesls closed this as completed Jan 14, 2015
@jamesls jamesls added the s3 label Jan 14, 2015
@pranavgarg
Copy link

usually in my case what was happening was there was an extra slash in the front of the key which was causing this issue. Fixing the key name helped overcome this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. s3
Projects
None yet
Development

No branches or pull requests

4 participants