lucasnadalutti
lucasnadalutti

Reputation: 5948

S3 bucket script to add timestamp in filename on upload

I'm looking for a way to add a timestamp in every file that is uploaded to an S3 bucket, Amazon-side. There is, of course, an option to do this client-side before the upload, but I don't think this is as nice and clean as it would be to have some script to run in the bucket itself everytime a new file is uploaded. I didn't find anything in the docs, though.

Upvotes: 0

Views: 3400

Answers (2)

John Rotenstein
John Rotenstein

Reputation: 269911

There is no capability within Amazon S3 to change the Key (filename) of a file based upon upload time.

Given that your desire is to avoid name conflicts, some choices are:

  • Use a unique GUID or a timestamp to name the file when uploading. This will avoid naming conflicts.
  • Upload the file to Bucket A, then use a Lambda function triggered on ObjectCreation to copy the object to Bucket B with a unique name based on timestamp

Upvotes: 4

cdelmas
cdelmas

Reputation: 860

You can try with a lambda function handling the ObjectCreated event. See this tutorial.

Not sure that works though.

Upvotes: 0

Related Questions