We are doing regular SQL dumps of Prod SQL database on EC2 to AWS S3 for backup purpose. Management needs latest dump to be downloaded from S3 to a different EC2 having test database. After download, the database in test server should automatically be updated with latest data from the downloaded dump. All this needs to be done without any manual intervention
CLI has not been configured in any servers for better security. To upload dumps from Prod server, we have attached IAM role to that EC2 server.
We tried to downoad the latest dump file using solution mentioned in this question.
However we are unable to download the file. The last part about key is bit confusing.
Last but not least, drop that into aws s3 cp to download the object:
KEY=
aws s3 ls $BUCKET --recursive | sort | tail -n 1 | awk '{print $4}'
aws s3 cp s3://$BUCKET/$KEY ./latest-object
Is there a way to do this using any scripting or AWS services?