DEV Community

Cover image for Working with S3 Object Tags in Buckets: SET, MERGE and CLEAR
ANSHUL VAIBHAV
ANSHUL VAIBHAV

Posted on

Working with S3 Object Tags in Buckets: SET, MERGE and CLEAR

A practical walkthrough for keeping Amazon S3 objects organized without changing what is inside the files.

Object tags are easy to overlook when you are busy uploading and moving files around S3. But once a bucket starts filling up, a few consistent labels can make objects easier to organize and manage. The part that matters is how you update them: replacing a tag set is not the same as adding a tag to what is already there.

I used Buckets by Serverless Creed to explore three useful actions—SET, MERGE and CLEAR—and checked the results in the AWS S3 console. I also compared the downloaded files with their original SHA-256 hashes to make sure the contents stayed exactly the same.

A quick look at object tags

An S3 object tag is a key-value pair attached to an object. For example, env=test, team=intern or phase=review can describe where a file belongs or how it is used. These are separate from the file itself and from ordinary user-defined object metadata. S3 allows up to ten tags per object.

Tags can be useful for organizing data and for AWS features that are configured to use them, including lifecycle rules and some access-control policies. That is why updating tags deserves a little more care than simply changing a filename.

Start with a small sample folder

I worked with a handful of harmless text files in a private S3 bucket:

  docs/readme.txt
  b.txt
  c.txt
  control.txt
Enter fullscreen mode Exit fullscreen mode

The files were small enough to inspect easily. The bulk operations shown below target only b.txt and c.txt. I left control.txt with a separate control=keep tag so there was always an object to compare against the ones being updated.

The sample files as they appear in the Buckets object browser.

The sample files as they appear in the Buckets object browser.

SET: replace the existing tags

SET is the option to choose when an object needs a completely new tag set. In Buckets, select the files, open the bulk tagging action and choose Set (replace). For this example, I entered team=intern.

The important word is replace: tags that were on the object before, but are not included in the new set, will be removed. Before applying the change, the dialog shows the exact object keys being updated. It is worth reading that list rather than assuming every visible folder or file is included.

SET preview in Buckets, with the new team tag and the exact object list.

SET preview in Buckets, with the new team tag and the exact object list.

The operation completes and Buckets displays the update result.

The operation completes and Buckets displays the update result.

Buckets reported Updated: 2, Failed: 0 for SET.

I then opened the object details in AWS. The tag panel showed one tag, team=intern, which is the state I expected after a replacement.

AWS S3 shows the new tag set after SET.

AWS S3 shows the new tag set after SET.

MERGE: add a tag without losing the others

MERGE is more useful when the existing labels should stay. I kept team=intern, switched to Merge, and entered a new tag: phase=review. I left the remove-keys field empty.

That should leave both tags on the objects. If a tag key already exists, MERGE updates that key; keys not mentioned are preserved. This is usually a safer option for incremental changes than rebuilding the full tag list by hand.

MERGE adds phase=review while preserving the other tag keys.

MERGE adds phase=review while preserving the other tag keys.

The MERGE action completes successfully.

The MERGE action completes successfully.

Buckets reported Updated: 2, Failed: 0 for MERGE.

The AWS object details now displayed both team=intern and phase=review. Checking the entire tag list is useful here: seeing only the new key would not prove that the earlier one survived.

Both team and phase are visible in the AWS object-tag panel.

Both team and phase are visible in the AWS object-tag panel.

CLEAR: remove tags, not the object

CLEAR does exactly what the name suggests: it removes the object’s tag set. In Buckets, choose Clear all after selecting the intended files. The confirmation makes the scope explicit and warns that tag-dependent lifecycle rules or policies may no longer match.

This is the step where I would be most careful in a real bucket. Clearing tags does not delete a file, but tags may be used by other AWS configurations. Always check the objects listed in the confirmation before proceeding.

CLEAR warns about removing all tags and shows the affected object keys.

CLEAR warns about removing all tags and shows the affected object keys.

Buckets confirms that the tag-removal operation completed.

Buckets confirms that the tag-removal operation completed.

Buckets reported Updated: 2, Failed: 0 for CLEAR.

Afterward, the AWS object details showed Tags (0). The AWS object details still identified b.txt; the wider Buckets capture also shows readme.txt remaining in the browser after tag removal. That distinction is important: removing tags is not the same thing as deleting objects.

The S3 tag section is empty after CLEAR.

The S3 tag section is empty after CLEAR.

A wider view of the Buckets object browser after tag removal.

A wider view of the Buckets object browser after tag removal.

The AWS object details page still shows the file and its empty tag set.

The AWS object details page still shows the file and its empty tag set.

Independent verification and SHA-256 integrity checking

I kept control.txt out of the tagging changes. Its control=keep tag was still there at the end, which was a quick check that the untouched object had retained its original tag.

The control object keeps its original tag.

The control object keeps its original tag.

For file contents, I recorded SHA-256 hashes of the original text files before uploading them. After the tagging sequence, I downloaded the S3 objects into a separate folder and compared them with that original hash list. Run the check from the download folder, with the original hash list one directory above it:

shasum -a 256 -c ../original-hashes.txt
Enter fullscreen mode Exit fullscreen mode

All four downloaded files match their original SHA-256 hashes.

All four downloaded files match their original SHA-256 hashes.

The output was:

docs/readme.txt: OK
b.txt: OK
c.txt: OK
control.txt: OK
Enter fullscreen mode Exit fullscreen mode

The AWS Console screenshot lists CRC64NVME as its stored checksum function. The SHA-256 verification here is a separate local comparison of the downloaded bytes against the original files.

All four checks returned OK. That gives two independent views of the outcome: the AWS Console shows how the tags changed, and the hash check shows that the downloaded file bytes matched the originals.

A few habits worth keeping

Three things made this workflow straightforward. First, use SET only when replacing the full tag set is intentional; use MERGE when existing labels should remain. Second, review the exact object list before any bulk operation, especially when folders and nested files are involved. Third, check the resulting tags in S3 rather than relying on a success message alone.

For a small example like this, the difference between SET, MERGE and CLEAR is easy to see. On a busy bucket, choosing the right operation—and verifying the final state—can save a lot of confusion later.

Top comments (0)