Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Copy link

@alexanderczigler alexanderczigler commented Jun 20, 2015

Nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.