AWS S3 versioning

Published: Friday, Apr 22, 2016 Last modified: Monday, Dec 9, 2024

Yes, versioning on my bucket is enabled!

/tmp/test$ aws --profile example s3 ls s3://s3test.jptdev.com/test.txt
2016-04-22 11:29:29         50 test.txt

Make changes to test.txt.

/tmp/test$ aws --profile example s3 cp test.txt s3://s3test.jptdev.com/
upload: ./test.txt to s3://s3test.jptdev.com/test.txt

Notice the aws-cli/1.10.20’s list-object-versions seems to work with prefix not key.

aws --profile example s3api list-object-versions --bucket s3test.jptdev.com --prefix test.txt
{
	"Versions": [
		{
			"LastModified": "2016-04-22T03:29:29.000Z",
			"VersionId": "lzDLKsb_Dgq5nMOe8pAotZszO6.cs5eq",
			"ETag": "\"2fe9901004a6ec6ec047f53c7e185e6d\"",
			"StorageClass": "STANDARD",
			"Key": "test.txt",
			"Owner": {
				"DisplayName": "hendry",
				"ID": "d68f9f3b34a478c25469ceb76ca6772fe9d3b02488a908f0562e93084c4294f7"
			},
			"IsLatest": true,
			"Size": 50
		},
		{
			"LastModified": "2016-04-22T03:17:14.000Z",
			"VersionId": "DVgKQiDzCpK_vZ8am6KxP7DDPg4oNAys",
			"ETag": "\"2fe9901004a6ec6ec047f53c7e185e6d\"",
			"StorageClass": "STANDARD",
			"Key": "test.txt",
			"Owner": {
				"DisplayName": "hendry",
				"ID": "d68f9f3b34a478c25469ceb76ca6772fe9d3b02488a908f0562e93084c4294f7"
			},
			"IsLatest": false,
			"Size": 50
		},
		{
			"LastModified": "2016-04-22T03:14:58.000Z",
			"VersionId": "3FF6_QlVwFCbXTTqYJqvIMHOh9uD_Zb0",
			"ETag": "\"c9d3df23822ab54e39af74471eaa9f68\"",
			"StorageClass": "STANDARD",
			"Key": "test.txt",
			"Owner": {
				"DisplayName": "hendry",
				"ID": "d68f9f3b34a478c25469ceb76ca6772fe9d3b02488a908f0562e93084c4294f7"
			},
			"IsLatest": false,
			"Size": 34
		},
		{
			"LastModified": "2016-04-22T03:14:49.000Z",
			"VersionId": "NhFpF7hak4qe7zg0bbGIQmk6QYqyC2q9",
			"ETag": "\"e59ff97941044f85df5297e1c302d260\"",
			"StorageClass": "STANDARD",
			"Key": "test.txt",
			"Owner": {
				"DisplayName": "hendry",
				"ID": "d68f9f3b34a478c25469ceb76ca6772fe9d3b02488a908f0562e93084c4294f7"
			},
			"IsLatest": false,
			"Size": 12
		}
	]
}

/tmp/test$ aws --profile example s3api get-object --bucket s3test.jptdev.com --key test.txt --version-id NhFpF7hak4qe7zg0bbGIQmk6QYqyC2q9 foo.txt
{
	"AcceptRanges": "bytes",
	"ContentType": "text/plain",
	"LastModified": "Fri, 22 Apr 2016 03:14:49 GMT",
	"ContentLength": 12,
	"VersionId": "NhFpF7hak4qe7zg0bbGIQmk6QYqyC2q9",
	"ETag": "\"e59ff97941044f85df5297e1c302d260\"",
	"Metadata": {}
}
/tmp/test$ cat foo.txt
Hello World