Aws S3 Filter by Tags. Search by tags

前端 未结 6 1707
北海茫月
北海茫月 2021-02-05 02:12

We have our bucket with new Aws SDK API on AWS S3. We uploaded and tagged lots of files and folders with tags.

How can we filter on key-value tag, or only one of them?

6条回答
  •  不要未来只要你来
    2021-02-05 03:01

    There's no way to filter/search by tags. But you can implement this yourself using S3.

    You can create a special prefix in a bucket, e.g. /tags/. Then for each actual object you add and want to assign a tag (e.g. Department=67), you add a new object in /tags/, e.g: /tags/XXXXXXXXX_YYYYYYYYY_ZZZZZZZZZ, where

    XXXXXXXXX = hash('Department')
    YYYYYYYYY = hash('67')
    ZZZZZZZZZ = actualObjectKey
    

    Then when you want to get all objects that have a particular tag assigned (e.g. Department), you have to execute the ListObjectsV2 S3 API for prefix /tags/XXXXXXXXX_. If you want objects that have particular tag value (e.g. Department=67), you have to execute the ListObjectsV2 S3 API for prefix /tags/XXXXXXXXX_YYYYYYYYY_

    https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html

    It's not that fast but still does the job.

    Obvious downside is that you have to remove the tags yourself. For example, you can do all of this above with a S3 triggers and lambda.

提交回复
热议问题