Giter Site home page Giter Site logo

s3.ErrCodeAccessDenied is missing about aws-sdk HOT 8 CLOSED

aws avatar aws commented on July 24, 2024
s3.ErrCodeAccessDenied is missing

from aws-sdk.

Comments (8)

diehlaws avatar diehlaws commented on July 24, 2024

Hi @rittneje, thanks for reaching out to us. At present, the SDK relies on the XML body of S3's response to determine the error received, since S3 does not return a body in the response of a HEAD request the SDK cannot reliably determine the error code returned for these operations. We've reached out to the S3 team internally in the past about modeling NotFound and AccessDenied errors for HEAD operations to S3 (see aws/aws-sdk-go#2593 for more details), however since this would present a breaking change in S3's behavior they have decided not to model these errors in a way that would result in constants that can be used to handle these errors for HeadObject and HeadBucket operations.

from aws-sdk.

rittneje avatar rittneje commented on July 24, 2024

@diehlaws Can you provide a code sample as to how we should be checking for the two errors mentioned in the documentation ("no such key" and "access denied")?

from aws-sdk.

skotambkar avatar skotambkar commented on July 24, 2024

@rittneje Here's a sample code showing how to check for no such key error; For Access denied exception, since we do not model the error code for it, a way would be to lookup string in the err.Error()

input := &s3.HeadObjectInput{
    Bucket: aws.String("examplebucket"),
    Key:    aws.String("HappyFace.jpg"),
}

result, err := svc.HeadObject(input)
if err != nil {
    if aerr, ok := err.(awserr.Error); ok {
        switch aerr.Code() {
        case ErrCodeNoSuchKey:
       		fmt.Println("error: no such key")
        case ErrCodeNoSuchUpload:
       		fmt.Println("error: no such upload")
        default:
           	fmt.Println(aerr.Error())
        }
    } else {
        // Print the error, cast err to awserr.Error to get the Code and
        // Message from an error.
        fmt.Println(err.Error())
    }
    return
}

fmt.Println(result)

Hope this helps. Let us know if you have any questions/feedback.

from aws-sdk.

rittneje avatar rittneje commented on July 24, 2024

Thanks for the code sample. I would request that the documentation of HeadObject be updated to more clearly explain how to check for those errors. The way it's currently written (pasted in my original comment) is too vague, in my opinion.
Also, from testing we found that we can do aerr.Code() == "Forbidden" for the "access denied" case.

from aws-sdk.

diehlaws avatar diehlaws commented on July 24, 2024

Thanks for the feedback @rittneje. Unfortunately we're unable to modify the description for the HeadObject call specifically since this originates from the service's API model, however we'll look into adding a note about this in the Overview section of the s3 package's documentation.

from aws-sdk.

jmklix avatar jmklix commented on July 24, 2024

P51417825

from aws-sdk.

jmklix avatar jmklix commented on July 24, 2024

Closing issue as the documentation has been updated:

A HEAD request has the same options as a GET action on an object. The response is identical to the GET response except that there is no response body. Because of this, if the HEAD request generates an error, it returns a generic 404 Not Found or 403 Forbidden code. It is not possible to retrieve the exact exception beyond these error codes.

from aws-sdk.

github-actions avatar github-actions commented on July 24, 2024

This issue is now closed.

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

from aws-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.