Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Update</h2> <p>As <a href="https://stackoverflow.com/a/21081892/45773">pointed out by alberge</a> (+1), nowadays the excellent <a href="https://aws.amazon.com/cli/" rel="noreferrer">AWS Command Line Interface</a> provides the most versatile approach for interacting with (almost) all things AWS - it meanwhile covers most services' APIs and also features <em>higher level S3 commands</em> for dealing with your use case specifically, see the <a href="http://docs.aws.amazon.com/cli/latest/reference/s3/index.html" rel="noreferrer">AWS CLI reference for S3</a>:</p> <ul> <li><a href="http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html" rel="noreferrer">sync</a> - <em>Syncs directories and S3 prefixes.</em> Your use case is covered by <a href="http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html#examples" rel="noreferrer">Example 2</a> (more fine grained usage with <code>--exclude</code>, <code>--include</code> and prefix handling etc. is also available): <blockquote> <p>The following sync command syncs objects under a specified prefix and bucket to objects under another specified prefix and bucket by copying s3 objects. [...] </p> <pre><code>aws s3 sync s3://from_my_bucket s3://to_my_other_bucket </code></pre> </blockquote></li> </ul> <p>For completeness, I'll mention that the <em>lower level S3 commands</em> are also still available via the <a href="http://docs.aws.amazon.com/cli/latest/reference/s3api/index.html" rel="noreferrer">s3api</a> sub command, which would allow to directly translate any SDK based solution to the AWS CLI before adopting its higher level functionality eventually.</p> <hr> <h2>Initial Answer</h2> <p>Moving files between S3 buckets can be achieved by means of the <a href="http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectCOPY.html" rel="noreferrer">PUT Object - Copy API</a> (followed by <a href="http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectDELETE.html" rel="noreferrer">DELETE Object</a>):</p> <blockquote> <p>This implementation of the PUT operation creates a copy of an object that is already stored in Amazon S3. A PUT copy operation is the same as performing a GET and then a PUT. Adding the request header, x-amz-copy-source, makes the PUT operation copy the source object into the destination bucket. <a href="http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html" rel="noreferrer">Source</a></p> </blockquote> <p>There are respective samples for all existing AWS SDKs available, see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/CopyingObjectsUsingAPIs.html" rel="noreferrer">Copying Objects in a Single Operation</a>. Naturally, a scripting based solution would be the obvious first choice here, so <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/CopyingObjectUsingRuby.html" rel="noreferrer">Copy an Object Using the AWS SDK for Ruby</a> might be a good starting point; if you prefer Python instead, the same can be achieved via <a href="https://github.com/boto/boto" rel="noreferrer">boto</a> as well of course, see method <code>copy_key()</code> within boto's <a href="http://boto.readthedocs.org/en/latest/ref/s3.html" rel="noreferrer">S3 API documentation</a>.</p> <p><code>PUT Object</code> only copies files, so you'll need to explicitly delete a file via <code>DELETE Object</code> still after a successful copy operation, but that will be just another few lines once the overall script handling the bucket and file names is in place (there are respective examples as well, see e.g. <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/DeletingOneObject.html" rel="noreferrer">Deleting One Object Per Request</a>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload