Skip to content

Instantly share code, notes, and snippets.

@mikebroberts
Created June 16, 2014 22:23
Show Gist options
  • Save mikebroberts/4c7c1fb6bc7e38dea5c1 to your computer and use it in GitHub Desktop.
Save mikebroberts/4c7c1fb6bc7e38dea5c1 to your computer and use it in GitHub Desktop.
Copy S3 objects while updating metadata and permissions
; Should eventually create a pull-request for https://github.com/weavejester/clj-aws-s3
(defn- create-copy-request [src-bucket src-key dest-bucket dest-key metadata permissions]
(let [req (CopyObjectRequest. src-bucket src-key dest-bucket dest-key)]
(when metadata
(.setNewObjectMetadata req (map->ObjectMetadata metadata)))
(when permissions
(.setAccessControlList req (create-acl permissions)))
req))
(defn copy-object-mr
"Copy an existing S3 object to another key. Returns a map containing
the data returned from S3"
([cred bucket src-key dest-key]
(copy-object cred bucket src-key bucket dest-key))
([cred src-bucket src-key dest-bucket dest-key & [metadata & permissions]]
(let [^CopyObjectRequest req (create-copy-request src-bucket src-key dest-bucket dest-key metadata permissions)]
(to-map (.copyObject (s3-client cred) req))
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment