Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to touch() a file in Amazon S3?

I'm currently working with Amazon S3 and I am writing a program that uses the modified dates. I'm looking for a way to edit the modified dates.

I could loop trough all the files and save them as they are, but this sounds like a bad solution.

In PHP there is this function touch().

Does anyone know a solution, or has the same problem?

like image 740
Ron van der Heijden Avatar asked Nov 19 '12 13:11

Ron van der Heijden


People also ask

Can I read S3 file without downloading?

Reading objects without downloading them Similarly, if you want to upload and read small pieces of textual data such as quotes, tweets, or news articles, you can do that using the S3 resource method put(), as demonstrated in the example below (Gist).

How do I access files on my S3 AWS?

In the Amazon S3 console, choose your S3 bucket, choose the file that you want to open or download, choose Actions, and then choose Open or Download. If you are downloading an object, specify where you want to save it. The procedure for saving the object depends on the browser and operating system that you are using.

How do I read S3 files in glue?

S3 URL: Enter the path to the Amazon S3 bucket, folder, or file that contains the data for your job. You can choose Browse S3 to select the path from the locations available to your account. Recursive: Choose this option if you want AWS Glue Studio to read data from files in child folders at the S3 location.

What is S3Uri?

S3Uri : represents the location of a S3 object, prefix, or bucket. This must be written in the form s3://mybucket/mykey where mybucket is the specified S3 bucket, mykey is the specified S3 key.


2 Answers

In response to @Daniel Golden's comment on @tkotisis answer. It looks like at least the AWS CLI tools do not let you copy an item on to itself. You can however 'force' a copy by updating the metadata.

$ aws s3 cp --metadata '{"touched":"now"}' s3://path/to/object s3://path/to/object 

This recreates the object (downloads to the caller and reuploads it) replacing its content, owner and metadata. This will also trigger any attached Lambda events.

like image 145
Jason Avatar answered Oct 15 '22 08:10

Jason


You can achieve the same through a copy object request, specifying the CopySource to be same as the target key.

In essence, this will issue a PUT Object - COPY request to S3 with the corresponding source and target bucket/key.

like image 23
tkotisis Avatar answered Oct 15 '22 08:10

tkotisis