Aws-cli: Recursively change storage class on bucket

Created on 10 Jul 2016  路  4Comments  路  Source: aws/aws-cli

How does one recursively change all objects on a bucket to STANDARD_IA with aws s3?

http://docs.aws.amazon.com/AmazonS3/latest/dev/ChgStoClsOfObj.html

Bonus: A way of defining a default storage class in ~/.aws/config

closing-soon guidance s3 service-api

Most helpful comment

You can do it by running this command:

$ aws s3 cp s3://knapp-standard-ia s3://knapp-standard-ia --recursive --storage-class STANDARD_IA
copy: s3://knapp-standard-ia/foo.py to s3://knapp-standard-ia/foo.py
copy: s3://knapp-standard-ia/100MB to s3://knapp-standard-ia/100MB

And then if you check the contents, the class should be STANDARD_IA:

$ aws s3api list-objects --bucket knapp-standard-ia
{
    "Contents": [
        {
            "LastModified": "2016-07-12T19:37:40.000Z", 
            "ETag": "\"0c4af570340e15f2be9924e70bc34257-13\"", 
            "StorageClass": "STANDARD_IA", 
            "Key": "100MB", 
            "Owner": {
                "DisplayName": "kylekaws", 
                "ID": "876e6c081ece589308db3ea341721492c49ad27397678f075c6deeeb6935a80f"
            }, 
            "Size": 104857600
        }, 
        {
            "LastModified": "2016-07-12T19:37:41.000Z", 
            "ETag": "\"d9ccfaeb76cd014d2551753ac45b8b98\"", 
            "StorageClass": "STANDARD_IA", 
            "Key": "foo.py", 
            "Owner": {
                "DisplayName": "kylekaws", 
                "ID": "876e6c081ece589308db3ea341721492c49ad27397678f075c6deeeb6935a80f"
            }, 
            "Size": 825
        }
    ]
}

I am not sure storage class is something we would want to define in the config file. It is pretty specific. It would need to be something more general like setting default parameters.

Let us know if that helps.

All 4 comments

You can do it by running this command:

$ aws s3 cp s3://knapp-standard-ia s3://knapp-standard-ia --recursive --storage-class STANDARD_IA
copy: s3://knapp-standard-ia/foo.py to s3://knapp-standard-ia/foo.py
copy: s3://knapp-standard-ia/100MB to s3://knapp-standard-ia/100MB

And then if you check the contents, the class should be STANDARD_IA:

$ aws s3api list-objects --bucket knapp-standard-ia
{
    "Contents": [
        {
            "LastModified": "2016-07-12T19:37:40.000Z", 
            "ETag": "\"0c4af570340e15f2be9924e70bc34257-13\"", 
            "StorageClass": "STANDARD_IA", 
            "Key": "100MB", 
            "Owner": {
                "DisplayName": "kylekaws", 
                "ID": "876e6c081ece589308db3ea341721492c49ad27397678f075c6deeeb6935a80f"
            }, 
            "Size": 104857600
        }, 
        {
            "LastModified": "2016-07-12T19:37:41.000Z", 
            "ETag": "\"d9ccfaeb76cd014d2551753ac45b8b98\"", 
            "StorageClass": "STANDARD_IA", 
            "Key": "foo.py", 
            "Owner": {
                "DisplayName": "kylekaws", 
                "ID": "876e6c081ece589308db3ea341721492c49ad27397678f075c6deeeb6935a80f"
            }, 
            "Size": 825
        }
    ]
}

I am not sure storage class is something we would want to define in the config file. It is pretty specific. It would need to be something more general like setting default parameters.

Let us know if that helps.

Thanks Kyle, I hope that goes into the man page / documentation as an example.

@kyleknap,

Sorry for excavating a such old issue.

Just to warn other users who will use a command. The method you supplied will duplicate objects in case if bucket versioning is enabled (hence double the price).

Just curious - where i can submit a request to reduce S3 to S2 (as it is not simple)?

WIll this change of storage class charge for data transfer?

Was this page helpful?
0 / 5 - 0 ratings