aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.66k stars 640 forks source link

S3 missing an error type for NoSuchTagSet #2878

Open taylor-sutton opened 10 months ago

taylor-sutton commented 10 months ago

Describe the bug

As per https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketTagging.html - the GetBucketTagging operation can return with a code NoSuchTagSet. However in s3 types, there is no corresponding error type.

Expected Behavior

I am able to refer to a types.NoSuchTagSet to type-safely check for this error.

Current Behavior

I get the following:

operation error S3: GetBucketTagging, https response error StatusCode: 404, RequestID: 1TQC5RB7RETDG6W9, HostID: 4seX6a1w9R//EtPng9skN/1cjcXuiBTsJ3IHxd0abABvoThEYi2wrC4KgAudD0VBM7AUPE4fFTw=, api error NoSuchTagSet: The TagSet does not exist

when showing the error via fmt.Printf("%+v\n", err)

Reproduction Steps

I am not sure the best way to create an S3 bucket that doesn't have any associated tag set, as opposed to having an empty tag set associated. In my case I see this for the bucket amazon-connect-1cc70ca065cd:


package main

import (
    "context"
    "fmt"

    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
    "github.com/aws/aws-sdk-go/aws"
)

func main() {
    ctx := context.Background()

    cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-west-2"))
    if err != nil {
        log.Fatalf("unable to load SDK config, %v", err)
    }

    client := s3.NewFromConfig(cfg)
    _, err = client.GetBucketTagging(ctx, &s3.GetBucketTaggingInput{
        Bucket: aws.String("amazon-connect-1cc70ca065cd"),
    })
    fmt.Printf("%+T; %+v\n", err, err)
}

Output:

*smithy.OperationError; operation error S3: GetBucketTagging, https response error StatusCode: 404, RequestID: BWJ5NJSVYNKETRXY, HostID: KZ6OuFYuikM5s/GvQnMFLYEv0cby+Tge7NowednJHnOkNdJa47WNTp3eKDjBYCDxZtGo3t/HCM9d4RdNIZ8LSQ==, api error NoSuchTagSet: The TagSet does not exist

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

Complete go.mod:

module s3_dr

go 1.21

require (
    github.com/aws/aws-sdk-go v1.49.13
    github.com/aws/aws-sdk-go-v2/config v1.26.2
    github.com/aws/aws-sdk-go-v2/service/s3 v1.47.7
)

require (
    github.com/aws/aws-sdk-go-v2 v1.24.0 // indirect
    github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect
    github.com/aws/aws-sdk-go-v2/credentials v1.16.13 // indirect
    github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect
    github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect
    github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect
    github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect
    github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.9 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.9 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.9 // indirect
    github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 // indirect
    github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect
    github.com/aws/aws-sdk-go-v2/service/sts v1.26.6 // indirect
    github.com/aws/smithy-go v1.19.0 // indirect
)

Compiler and Version used

go version go1.21.3 darwin/arm64

Operating System and version

macOS 14.2.1

RanVaknin commented 10 months ago

Hi @taylor-sutton ,

Thanks for reaching out. If you did not know, all of the AWS SDKs are code generated from the API models of each AWS service. In this case, S3 did not specify this as an error type in their model as you can see here (linking v1 model since v2 model is in raw format):

    "GetBucketTagging":{
      "name":"GetBucketTagging",
      "http":{
        "method":"GET",
        "requestUri":"/{Bucket}?tagging"
      },
      "input":{"shape":"GetBucketTaggingRequest"},
      "output":{"shape":"GetBucketTaggingOutput"},
      "documentationUrl":"http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETtagging.html",
      "staticContextParams":{
        "UseS3ExpressControlEndpoint":{"value":true}
      }
    },

As seen in this operation definition, this is missing an errors array containing all the possible errors an operation can return.

Here is an example of how a modeled error should look like:

    "HeadBucket":{
      "name":"HeadBucket",
      "http":{
        "method":"HEAD",
        "requestUri":"/{Bucket}"
      },
      "input":{"shape":"HeadBucketRequest"},
      "output":{"shape":"HeadBucketOutput"},
      "errors":[
        {"shape":"NoSuchBucket"}
      ],
      "documentationUrl":"http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketHEAD.html"
    },

Since the S3 team did not specify this as an error type in their API, the SDK will not generate a concrete type for it, and there is nothing we can do on the SDK side to introduce this without a model change. Here is a related issue on the JS SDK basically referring to the same problem with headBucket not modeling other errors. The S3 team is slow to introduce changes to their API model, so they supplement it by adding relevant documentation as seen in the doc string you linked.

Error code: NoSuchTagSet

Description: There is no tag set associated with the bucket.

So you could get around this by simply doing string comparison which should be safe.

    if err != nil {
        if strings.Contains(err.Error(), "NoSuchTagSet") {
            fmt.Println("NoSuchTagSet error occurred")
        }
    }

Thanks, Ran~

taylor-sutton commented 10 months ago

Hi @RanVaknin , thanks for your response. Is there an appropriate place I can nudge (or add to an existing nudge) the S3 team to update their data model?

Since it sounds like there is nothing on the SDK side, feel free to close this issue.

RanVaknin commented 10 months ago

Hi @taylor-sutton , Thanks for your patience.

I have created another internal ticket with the S3 team with very detailed instructions on what needs to change on their backend to make it as easy of a change as possible.

I just want to set your expectation that S3 is an enormous team both in terms of the size of the organization and the amount of work they handle, so it might take a while until this ticket makes it to the right person, and until it gets prioritzied. One thing you can do is create your own internal ticket via the AWS developer console and refer to the ticket I have created P112680375. This should help push this in the right direction.

Transferring to the cross-sdk repo for further tracking.

Thanks again, Ran~