Skip to content

Instantly share code, notes, and snippets.

@joech4n
Last active February 11, 2018 04:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joech4n/953c1cd6a36698c5d120 to your computer and use it in GitHub Desktop.
Save joech4n/953c1cd6a36698c5d120 to your computer and use it in GitHub Desktop.
AWS Lambda Function to change ownership on each object created to the bucket owner. It accomplishes this by overwriting the key with itself. This is to be triggered by an S3 ObjectCreated (All) Event.
@williamtsoi1
Copy link

Hi,

Thanks for this code. This was very useful for me as I needed something to do this.

However, I think there's a bug in here, because running the code as-is causes an infinite loop. Each time the file gets overwritten by the lambda, another instance of the lambda gets invoked due to the S3 ObjectCreated (All) event, and this repeats itself ad-infinitum.

Here's my version of the solution, which does a check on the ownership of the S3 object against the running AWS account before deciding on whether to go through with the s3.CopyObject() operation or not.

https://gist.github.com/williamtsoi1/104531c65852a852399a3dc1096a2dcc

Thanks once again!

@joech4n
Copy link
Author

joech4n commented Mar 2, 2017

@williamtsoi1 thanks for the update!

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