How To Get The Largest Gadgets In An S3 Bucket

How To Get The Largest Gadgets In An S3 Bucket

AWS Logo

Should you’re curious concerning the largest gadgets in an AWS S3 bucket, you need to use the CLI to print out a listing sorted by measurement. This might help you find unusually massive objects within the bucket which can be taking over house.

Itemizing and Sorting Gadgets with the S3 CLI

S3 supplies some inbuilt sorting choices within the menus, so in case you’re simply in search of the most important merchandise in a folder, you may merely kind that folder. Nonetheless, if you wish to seek for all gadgets no matter key, you’ll want to take action from the AWS CLI. Should you don’t have that put in, you may refer to our guide on configuring it to set it up.

The command for itemizing objects is fairly easy:

aws s3api list-object-versions --bucket example-bucket

This question can take some time to judge, because it’s downloading a grasp record of all objects and their metadata, however you’ll get a JSON array containing an entry for every merchandise, like the next:

            "ETag": ""04e28fbee1ef2721123bb4e9a78183a895"",
            "Dimension": 320,
            "StorageClass": "STANDARD",
            "Key": "folder/file.json",
            "VersionId": "fNdwjJRaEjBYUSBgZe51oj_s4ONo5GsL",
            "IsLatest": false,
            "LastModified": "2020-11-05T18:59:18+00:00",
            "Proprietor": {
                "DisplayName": "username",
                "ID": "501092a155f88f4d174d7as3d2a347f33b9495f0261434682ab9a"

To parse and type this, you need to use jq — a implausible utility for working with JSON on the command line. You’ll be able to obtain it from apt, although binaries are also available:

sudo apt-get set up jq

This makes the ultimate command the next, which is able to nonetheless take some time to judge, however will print out the most important 100 gadgets within the bucket:

aws s3api list-object-versions --bucket oxide.rust | jq -r '.Variations[] | "(.Key)t (.Dimension)"' | kind -k2 -r -n | head -100

In order for you kind of gadgets, you may change the enter parameter to the head command, which trims all however the first N strains.

Source link