Skip to content
Software capabilities
Amazon S3

List Amazon S3 object versions and delete markers

Use ListObjectVersions when a bucket has versioning and an operator needs historical object versions or delete markers. Follow both key and version markers when the response is truncated.

Documentation reviewed · 2 methods with sources

Ways to do it

  1. API: GET ?versions
  2. CLI: aws s3api list-object-versions
API

GET ?versions

List versions and delete markers in a general purpose bucket. Use prefix to narrow the response.

Read source: Amazon S3 ListObjectVersions API
Requirements
A Signature Version 4 signed request, s3:ListBucketVersions on the bucket, and a regional bucket endpoint.
Limitations
When IsTruncated is true, pass NextKeyMarker and NextVersionIdMarker as key-marker and version-id-marker. Directory buckets do not support this operation.

Example text

GET /?versions&prefix=backups%2F&max-keys=100
CLI

aws s3api list-object-versions

Inspect version IDs, IsLatest flags, and delete markers from the AWS CLI.

Read source: AWS CLI list-object-versions reference
Requirements
AWS CLI configured for the target account and region, s3:ListBucketVersions, and a bucket name.
Limitations
The CLI returns a NextToken when its --max-items cap truncates output. Pass it to --starting-token for the next invocation.

Example shell

aws s3api list-object-versions --bucket "$S3_BUCKET" --prefix backups/ --max-items 100 --output json