Created
June 29, 2017 00:39
-
-
Save tiagomatos/53f61a0d3319eb6a43f6211d8d2d4661 to your computer and use it in GitHub Desktop.
Restore Deleted S3 Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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