~/snippets/s3-retrieving-an-object-from-history
Published on

Retrieving an S3 Object from history

121 words1 min read

The following instructions assume you have the relevant AWS environment variables set (e.g. AWS_ACCESS_KEY_ID) to allow authentication with your S3 bucket.

For demonstration purposes, this article assumes you're accessing a terraform.tfvars file in the location of s3://my-data/environment/live/objects/thisobject/terraform.tfvars.

List versions of the object

aws s3api list-object-versions --bucket my-data --prefix environment/live/objects/thisobject/terraform.tfvars

Retrieve a specific version

This section assumes a version of Dcqs8zCgSS84YWHu7xwDEr4RNd678eCa was retrieved from the previous step.

aws s3api get-object --bucket my-data --key environment/live/objects/thisobject/terraform.tfvars --version-id Dcqs8zCgSS84YWHu7xwDEr4RNd678eCa copied.tfvars

Now, if everything was successful, copied.tfvars will contain the item from history.