Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

S3 Bucket tagging fails with a NoSuchTagSet error #117

Closed
stevelitras opened this issue Oct 3, 2023 · 6 comments
Closed

S3 Bucket tagging fails with a NoSuchTagSet error #117

stevelitras opened this issue Oct 3, 2023 · 6 comments

Comments

@stevelitras
Copy link

I'm testing out auto-tag to tag all new resources in our accounts, and I've run into an issue. When I create a new S3 bucket, the lambda ends up getting invoked, but it dies with the following exception:

NoSuchTagSet: The TagSet does not exist

I'm wondering if this is due to changes in the AWS SDK that makes these errors and exception instead of a returned error via the promise.

@ryankenney-dev
Copy link

I'm seeing the same issue. It doesn't seem to fail if the bucket has more than zero tags already. Here's a related discussion that suggests S3 needs special handling of an empty tagset: boto/boto3#341

@ryankenney-dev
Copy link

Hrm...

Here's the exception I'm seeing:

2023-10-26T18:32:21.938Z	...	ERROR	Invoke Error 	
{
    "errorType": "NoSuchTagSet",
    "errorMessage": "The TagSet does not exist",
    "name": "NoSuchTagSet",
    "$fault": "client",
    "$metadata": {
        "httpStatusCode": 404,
        "extendedRequestId": "...",
        "attempts": 1,
        "totalRetryDelay": 0
    },
    "Code": "NoSuchTagSet",
    "BucketName": "...",
    "RequestId": "...",
    "HostId": "...",
    "message": "The TagSet does not exist",
    "stack": [
        "NoSuchTagSet: The TagSet does not exist",
        "    at throwDefaultError (/var/runtime/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22)",
        "    at deserializeAws_restXmlGetBucketTaggingCommandError (/var/runtime/node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:4180:43)",
        "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
        "    at async /var/runtime/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24",
        "    at async /var/runtime/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:13:20",
        "    at async StandardRetryStrategy.retry (/var/runtime/node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)",
        "    at async /var/runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22"
    ]
}

I'm running code built from the latest master, where I see special handling code that I would expect to handle the above:

// src/workers/autotag_s3_worker.js

  getExistingTags() {
    return new Promise((resolve, reject) => {
      try {
        this.s3.getBucketTagging({
          Bucket: this.getBucketName(),
        }, (err, res) => {
          if (err) {
            if (err.code === 'NoSuchTagSet' && err.statusCode === 404) {
              resolve([]);
            } else {
              reject(err);
            }
          } else {
            resolve(res.TagSet);
          }
        });
      } catch (e) {
        reject(e);
      }   
    }); 
  }

@ryankenney-dev
Copy link

This fixed it for me (note Code vs code):

auto-tag/src/workers/autotag_s3_worker.js

-            if (err.code === 'NoSuchTagSet' && err.statusCode === 404) {
+            if (err.Code === 'NoSuchTagSet') {

@rayjanoka
Copy link
Collaborator

thanks everyone, it should be resolved in v0.5.8!

@casper-gh
Copy link

@rayjanoka FYI - This issue still exists on v0.5.9. The fix is what @ryankenney-dev suggested.

@rayjanoka
Copy link
Collaborator

rayjanoka commented Nov 29, 2023

@nicholas-yong got it this time. thanks Nicholas! see v0.5.10

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants