Bootstrap FreeKB - Amazon Web Services (AWS) - List S3 Bucket LifeCycle Configuration
Amazon Web Services (AWS) - List S3 Bucket LifeCycle Configuration


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

An S3 Bucket is similar to an NFS share in that it is a mountable storage volume.

An S3 Bucket Lifecycle Configuration can be used to:

  • Move objects from one Storage Class to another Storage Class (e.g. from the Standard Storage Class to the Archive or Deep Archive Storage Class)
  • Delete objects

There is a cost to storage object in an S3 Bucket, and different Storage Classes have different costs.

The aws s3api list-buckets command can be used to list your S3 buckets.

~]$ aws s3api list-buckets
{
    "Buckets": [
        {
            "Name": "my-bucket-abcdefg",
            "CreationDate": "2023-06-02T02:22:19+00:00"
        }
    ],
    "Owner": {
        "DisplayName": "john.doe",
        "ID": "ab0e0a41234567893a77c82240d5abcdc41ff11c123456789c777a5123443743"
    }
}

 

Then the aws s3api get-bucket-lifecycle-configuration command can be used to list an S3 Bucket LifeCycle Configuration

~]$ aws s3api get-bucket-lifecycle-configuration --bucket my-bucket-abcdefg
{
    "Rules": [
        {
            "ID": "default",
            "Filter": {},
            "Status": "Enabled",
            "Transitions": [
                {
                    "Days": 1,
                    "StorageClass": "GLACIER_IR"
                }
            ]
        }
    ]
}

 

The aws s3api list-objects command can be used to list the objects (files) in your S3 Bucket.

aws s3api list-objects --bucket my-bucket-abcdefg

 

Something like this should be returned. Notice this includes StorageClass (STANDARD in this example).

[
    {
        "Key": "foo.txt",
        "LastModified": "2023-06-08T01:21:59+00:00",
        "ETag": "\"b1946ac9249abdg47c6235b4d1234184\"",
        "Size": 6,
        "StorageClass": "STANDARD",
        "Owner": {
            "DisplayName": "john.doe",
            "ID": "ab0e0a41e3abcd103a77c8224012343fc41ff11cc325c65b5c7abcgf8e743743"
        }
    }
]

 

The aws ce get-cost-and-usage command can be used to return the total cost for S3 in a certain time frame. In this example, the S3 total cost was a whopping $0.026 for January of 2024!

~]$ aws ce get-cost-and-usage --time-period Start=2024-01-01,End=2024-01-31 --granularity MONTHLY --metrics "BlendedCost" "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment --filter '{"Dimensions": {"Key": "SERVICE","Values": ["Amazon Simple Storage Service"]}}'
{
    "GroupDefinitions": [
        {
            "Type": "DIMENSION",
            "Key": "SERVICE"
        },
        {
            "Type": "TAG",
            "Key": "Environment"
        }
    ],
    "ResultsByTime": [
        {
            "TimePeriod": {
                "Start": "2024-01-01",
                "End": "2024-01-31"
            },
            "Total": {},
            "Groups": [
                {
                    "Keys": [
                        "Amazon Simple Storage Service",
                        "Environment$"
                    ],
                    "Metrics": {
                        "BlendedCost": {
                            "Amount": "0.2621694181",
                            "Unit": "USD"
                        },
                        "UnblendedCost": {
                            "Amount": "0.2621694181",
                            "Unit": "USD"
                        },
                        "UsageQuantity": {
                            "Amount": "481081.9302019198",
                            "Unit": "N/A"
                        }
                    }
                }
            ],
            "Estimated": false
        }
    ],
    "DimensionValueAttributes": []
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b203e7 in the box below so that we can be sure you are a human.