You can use the below command
$ aws s3 ls $BUCKET --recursive | sort | tail -n 1 | awk '{print $4}' some/other/object
Command explained
$ aws s3 ls $BUCKET --recursive -- Lists all the objects in bucket
$ aws s3 ls $BUCKET --recursive | sort -- Lists all the objects based on date
$ aws s3 ls $BUCKET --recursive | sort | tail -n 1 -- Selects the last line of the output ie most recent object
$ aws s3 ls $BUCKET --recursive | sort | tail -n 1 | awk '{print $4}' -- prints the name of most recent object
To learn more about Migrating to AWS, join our AWS Certification. Also, If you wish to master the principles of AWS and work on step-by-step tasks that have significant relevance for the world of business, industry professionals developed the AWS syllabus.