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 in Others by Edureka
• 9,320 points
61 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 by Edureka
• 8,820 points

Related Questions In Others

+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 in Others by Kichu
• 15,810 points
22 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 in Others by Kichu
• 15,810 points
46 views
0 votes
1 answer
0 votes
1 answer

How to create subnet inside a VPC in AWS using Terraform?

Hi@akhtar, You need to use aws_subnet resource inside your ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,340 points
147 views
0 votes
1 answer

How to convert data from txt files to Excel files using python

Hi , there are few steps to ...READ MORE

answered Feb 16 in Others by Edureka
• 9,320 points
1,217 views
0 votes
1 answer

Calculate Birthdate from an age using y,m,d in Excel

Hello, yes u can find your birthdate using ...READ MORE

answered Feb 16 in Others by Edureka
• 9,320 points
31 views
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 in Others by Edureka
• 8,820 points
110 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 in Others by Edureka
• 8,820 points
174 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP