Please fill out the sections below to help us address your issue.
8cf801c5ae5a71c4aad630556ce2e2c1d46ed8a2
go version)?1.10.3
The same thing as in #765 and #1208, apparently still happening. Basically, HeadObject is returning a NotFound error when it should be returning a NoSuchKey error.
func main() {
ses, err := session.NewSession()
if err != nil {
panic(err)
}
svc := s3.New(
ses,
)
_, err = svc.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String("realBucket"),
Key: aws.String("bar"),
})
fmt.Println(err)
_, err = svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String("realBucket"),
Key: aws.String("bar"),
})
fmt.Println(err)
}
Output
NotFound: Not Found
status code: 404, request id: <req-id>, host id: <host-id>
NoSuchKey: The specified key does not exist.
status code: 404, request id: <req-id>, host id: <host-id>
Would appreciate some help here! :)
Hey @rubensf, thanks for reaching out to us about this. The different error responses you're seeing from S3 between HeadObject and GetObject are defined by the service rather than the AWS SDK for Go. You can see the same difference in responses from S3 when using curl to HEAD and GET a nonexistent object in a bucket.
$ curl -I https://s3.amazonaws.com/<bucketname>/asdf
HTTP/1.1 404 Not Found
x-amz-request-id: RID
x-amz-id-2: HostID
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Fri, 10 Aug 2018 22:55:50 GMT
Server: AmazonS3
$ curl https://s3.amazonaws.com/<bucketname>/asdf
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>asdf</Key><RequestId>RID</RequestId><HostId>HostID</HostId></Error>
Since this behavior relates to the S3 service and is not specific to the AWS SDK for Go, I'd suggest posting about this in the AWS Forums for S3
Hi @diehlaws - thanks! Really appreciate the help.
I'll check on the forum.
Currently service/s3/errors.go doesn't declare anything like ErrCodeNotFound = "NotFound", while it does declare aliases for other error codes. (Many other service packages do declare ErrCodeNotFound".) I'd prefer not to keep AWS error code literals in my own codebase if it can be avoided - was there a rationale for leaving that one out or would it be acceptable to add that declaration?
Can I get a straight answer from someone please. I need help with an error code. I am not computer savvy at all. I could really use some help
Most helpful comment
Currently
service/s3/errors.godoesn't declare anything likeErrCodeNotFound = "NotFound", while it does declare aliases for other error codes. (Many other service packages do declareErrCodeNotFound".) I'd prefer not to keep AWS error code literals in my own codebase if it can be avoided - was there a rationale for leaving that one out or would it be acceptable to add that declaration?