Skip to content

Instantly share code, notes, and snippets.

@roparz
Created July 23, 2014 09:36
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save roparz/e9dedb2b8d421d75b989 to your computer and use it in GitHub Desktop.
Save roparz/e9dedb2b8d421d75b989 to your computer and use it in GitHub Desktop.
Rename object with Node.js AWS S3 (copy object then delete object) with promises
config = require 'config'
s3 = require 's3'
q = require 'q'
module.export = (oldKey, newKey) ->
defer = q.defer()
params =
# you need to set the s3 bucket in the CopySource key
CopySource: "#{ config.s3.bucket }/#{ oldKey }"
Key: newKey
s3.copyObject params, (err) ->
if err then defer.reject(err)
else s3.deleteObject Key: oldKey, (err) ->
if err then defer.reject(err)
else defer.resolve()
return defer.promise
@alexanderczigler
Copy link

Nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment