Get last modified object from S3 using AWS CLI

0 votes

I have a use case where I programmatically bring up an EC2 instance, copy an executable file from S3, run it and shut down the instance (done in user-data). I need to get only the last added file from S3.

Is there a way to get the last modified file / object from a S3 bucket using the AWS CLI tool?

Mar 21, 2022 in Others by Edureka
• 13,670 points
4,202 views

1 answer to this question.

0 votes

With aws s3 ls $BUCKET —recursive, you may see all the objects in the bucket.

$ aws s3 ls $BUCKET --recursive
2015-05-05 15:36:17          4 an_object.txt
2015-06-08 14:14:44   16322599 some/other/object
2015-04-29 12:09:29      32768 yet-another-object.sh
The first column is the last modified time, and they're arranged alphabetically by key. They'll be reordered by date if you do a quick sort:
$ aws s3 ls $BUCKET --recursive | sort
2015-04-29 12:09:29      32768 yet-another-object.sh
2015-05-05 15:36:17          4 an_object.txt
2015-06-08 14:14:44   16322599 some/other/object

answered Mar 24, 2022 by gaurav
• 23,260 points

Related Questions In Others

0 votes
0 answers
+1 vote
0 answers
0 votes
0 answers

AWS S3 object listing

I am using AWS-SDK using node.js. I want ...READ MORE

Apr 23, 2022 in Others by Kichu
• 19,050 points
923 views
0 votes
0 answers

How to get response from S3 getObject in Node.js?

I am attempting to get data back ...READ MORE

Apr 23, 2022 in Others by Kichu
• 19,050 points
1,616 views
0 votes
1 answer

How to get landmarks from current location using google map in iphone?

You can achieve this by saving several ...READ MORE

answered Sep 20, 2022 in Others by Aditya
• 7,680 points
320 views
0 votes
1 answer

How to get columns from Excel files using Apache POI?

The only way to see all the ...READ MORE

answered Oct 18, 2022 in Others by narikkadan
• 63,420 points
4,254 views
0 votes
1 answer

I Get "object required" error when using getElementByID

As you see LoginID is the id of the ...READ MORE

answered Jan 15, 2023 in Others by narikkadan
• 63,420 points
629 views
0 votes
1 answer
0 votes
1 answer

What does it mean when owner is None on an AWS S3 object?

S3 Object Ownership is an Amazon S3 ...READ MORE

answered Mar 15, 2022 in Others by gaurav
• 23,260 points
1,152 views
0 votes
1 answer

How to use AWS S3 CLI to dump files to stdout in BASH?

All file objects must have their contents ...READ MORE

answered Mar 24, 2022 in Others by gaurav
• 23,260 points
1,668 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP