I'm new to scripting and writing a Shell script to copy AWS S3 object from one AWS account bucket to another bucket? A pipeline uploads zip files (.zip) to a bucket. The shell script should only copy the last modified object(file). I know that in shell script, you can recursively find files based on wildcard matching and get last uploaded object from S3 CLI. Is there a more elegant and effective way of doing it?
# Normal way of copying from one bucket to another
aws s3 cp s3://source-bucket/object-v2.2.7.zip s3://destination- bucket/.
# Using the --recursive parameter to copy file
aws s3 ls $source-bucket --recursive | sort | tail -n 1 | awk '{print $4}'
get_object = `aws s3 ls $source-bucket --recursive | sort | tail -n 1 | awk '{print $4}'`
aws s3 cp s3://$get_object s3://destination-bucket
echo 'Successfully uploaded file to Destination Bucket'