in Education by
I have a use case where I programmatically bring up an EC2 instance, copy and 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 CLI ? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Yes, using the following commands in the CLI you can get the last modified objects in the bucket: Listing all the objects in the bucket: $ aws s3 ls $BUCKET --recursive Note: The objects in the displayed list will be sorted alphabetically by key. The first column that you will see will be the column of the modified time. Sorting the objects displayed in the list as per the last modified time: $ aws s3 ls $BUCKET --recursive | sort Note: The last row will display the last modified object along with its respective modified time. To select the last row and extract the name of the object from that row: $ aws s3 ls $BUCKET --recursive | sort | tail -n 1 | awk '{print $4}' 'tail -n' selects the last row awk '{print $4}' extracts the 4th column in the last row, which is the name of the object. To download the extracted object: $ aws s3 cp s3://$BUCKET/$KEY ./latest-object

Related questions

0 votes
    I am migrating my Java,Tomcat, Mysql server to AWS EC2. I have already attached EBS volume for storing MySql ... you guide. Thanks Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am migrating my Java,Tomcat, Mysql server to AWS EC2. I have already attached EBS volume for storing MySql ... you guide. Thanks Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Is it possible to get the ARN of an S3 bucket via the AWS command line? I have looked through the documentation ... way to do this. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm trying to set up an Amazon Linux AMI(ami-f0091d91) and have a script that runs a copy command to copy ... what is going on? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm starting a bash script which will take a path in S3 (as specified to the ls command) and dump the ... finding which does it? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Any easy way to move and custom AMI image between regions? (North Virginia -> Singapore) I know you can mess up with ... way to do it? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have my instance of the Amazon AWS running, the test page is up. I am trying to SFTP the files to ... move them, permission denied. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am using the aws cli to list the files in an s3 bucket using the following command (documentation): aws s3 ... only the file list? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm having trouble using * in the AWS CLI to select a subset of files from a certain bucket. Adding * to the ... s3://data/2016-08*. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am writing an API for an iOS app where the user's login with the Facebook API on iOS. The server ... achieve this kinda setup? Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
0 votes
    Are there use cases that lend themselves better to Amazon cloudfront over s3 or the other way around? I'm ... 2 through examples. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Can someone explain the basic difference that distinguishes s3n, s3a and s3 in Hadoop? Technically how are they different? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me how can I get the ARN for an S3 bucket using AWS Cli Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I've got a Node.js powered site that I'm running on Amazon Elastic Beanstalk. My Node.js app listens on port ... to my site via HTTPS. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How can I find out the instance id of an ec2 instance from within the ec2 instance? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
...