Enable File Versioning for a Bucket
  • 13 Dec 2022
  • 1 Minute to read
  • Dark
    Light

Enable File Versioning for a Bucket

  • Dark
    Light

Article summary

To enable file versioning for an S3 bucket, we recommend installing the AWS CLI, found here https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Once installed, run the configuration command, and enter your access key and secret key. 

aws configure

Now you can run the `put-bucket-versioning` command to enable versioning for any of your buckets. Keep in mind, once versioning is enabled for a bucket, it cannot be disabled. However, you can delete versions of individual objects to save storage space.

aws s3api put-bucket-versioning --bucket example-bucket --versioning-configuration Status=Enabled 

You can also use the `get-bucket-versioning` command to check the current versioning status of a bucket.

aws s3api get-bucket-versioning --bucket example-bucket 

This will return the versioning status for the `example-bucket` bucket. If versioning is enabled, the output will look something like this:

{ "Status": "Enabled" }

Once versioning is enabled, you can make use of the `list-object-versions` command to see all available versions of your files.

aws s3api list-object-versions \
    --bucket example-bucket \
    --endpoint https://s3.si.servercontrol.com.au

This will return a list of object versions, like this:

{
    "Versions": [
        {
            "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
            "Size": 0,
            "StorageClass": "STANDARD",
            "Key": "example.txt",
            "VersionId": "vht3sqYdwmtvDWd8ZfUxnqyGiz4txrx",
            "IsLatest": true,
            "LastModified": "2022-12-13T22:39:26.612000+00:00",
            "Owner": {
                "DisplayName": "ServersAustralia",
            }
        },
        {
            "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
            "Size": 0,
            "StorageClass": "STANDARD",
            "Key": "example.txt",
            "VersionId": "MbqyXDyHRo7-dkxDNmSP-2gHDI9YroK",
            "IsLatest": false,
            "LastModified": "2022-12-13T22:39:25.131000+00:00",
            "Owner": {
                "DisplayName": "ServersAustralia",
            }
        },
    ]
}

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence