Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 restore additions #408

Merged
merged 3 commits into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions boto3/data/s3/2006-03-01/resources-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,15 @@
{ "target": "Key", "source": "identifier", "name": "Key" }
]
}
},
"RestoreObject": {
"request": {
"operation": "RestoreObject",
"params": [
{ "target": "Bucket", "source": "identifier", "name": "BucketName" },
{ "target": "Key", "source": "identifier", "name": "Key" }
]
}
}
},
"batchActions": {
Expand Down Expand Up @@ -1013,6 +1022,15 @@
{ "target": "Key", "source": "identifier", "name": "Key" }
]
}
},
"RestoreObject": {
"request": {
"operation": "RestoreObject",
"params": [
{ "target": "Bucket", "source": "identifier", "name": "BucketName" },
{ "target": "Key", "source": "identifier", "name": "Key" }
]
}
}
},
"batchActions": {
Expand Down
30 changes: 30 additions & 0 deletions boto3/examples/s3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,33 @@ the objects in the bucket.
bucket = s3.Bucket('my-bucket')
for obj in bucket.objects.all():
print(obj.key)


Restore Glacier objects in an Amazon S3 bucket
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following example shows how to initiate restoration of glacier objects in
an Amazon S3 bucket, determine if a restoration is on-going, and determine if a
restoration is finished.

.. code-block:: python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an empty line here, to make it a valid REST syntax.


import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('glacier-bucket')
for obj_sum in bucket.objects.all():
obj = s3.Object(obj_sum.bucket_name, obj_sum.key)
if obj.storage_class == 'GLACIER':
# Try to restore the object if the storage class is glacier and
# the object does not have a completed or ongoing restoration
# request.
if obj.restore is None:
print('Submitting restoration request: %s' % obj.key)
obj.restore_object()
# Print out objects whose restoration is on-going
elif 'ongoing-request="true"' in obj.restore:
print('Restoration in-progress: %s' % obj.key)
# Print out objects whose restoration is complete
elif 'ongoing-request="false"' in obj.restore:
print('Restoration complete: %s' % obj.key)