Skip to content

Instantly share code, notes, and snippets.

@tiagomatos
Created June 29, 2017 00:39
Show Gist options
  • Save tiagomatos/53f61a0d3319eb6a43f6211d8d2d4661 to your computer and use it in GitHub Desktop.
Save tiagomatos/53f61a0d3319eb6a43f6211d8d2d4661 to your computer and use it in GitHub Desktop.
Restore Deleted S3 Objects
# make sure you have the IAM policy allowed to do: "s3:DeleteObject"
# read: http://docs.aws.amazon.com/AmazonS3/latest/dev/RemDelMarker.html
client = Aws::S3::Client.new
ovs = client.list_object_versions(bucket: 'bucket-name', prefix: "store/store-name/")
ovs.delete_markers.each do |ov|
p "key: #{ov.key} - latest: #{ov.is_latest} - last_modified: #{ov.last_modified}"
client.delete_object({ bucket: 'bucket-name', key: ov.key, version_id: ov.version_id }) # the important part here is deleting the correct version.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment