wilean0120
wilean0120

Reputation: 21

Stop multiple RDS instances using AWS CLI command

I have been trying to stop multiple instances of RDS using a single command line but it does not seem to work.

Currently I can only make it work with one instance at a time with a command like this:

aws rds stop-db-instance --db-instance-identifier test-instance1 --region ap-southeast-1 --profile dev

However I would like to stop multiple RDS and this does not seem to work:

aws rds stop-db-instance --db-instance-identifier test-instance1 test-instance2 testinstance3 --region ap-southeast-1 --profile dev

Any idea or suggestion on how I can make this work?

If it is not possible I will probably create a CRON job instead using Lambda.

Upvotes: 1

Views: 1817

Answers (2)

jarmod
jarmod

Reputation: 78653

If writing a shell script that calls aws rds stop-db-instance multiple times, once per RDS instance, is problematic for you somehow, then consider doing this via a scheduled Lambda (think of it like crontab).

See Schedule Amazon RDS stop and start using AWS Lambda, which:

presents a solution using AWS Lambda and Amazon EventBridge that allows you to schedule a Lambda function to stop and start the idle databases with specific tags to save on compute costs.

Upvotes: 0

Marcin
Marcin

Reputation: 238199

Sadly you can't do this. But you can write a simple bash for loop:

ids=(test-instance1 test-instance2 test-instance3)

for id in ${ids[@]}; 
do
    echo "Stopping: ${id}" 
    aws rds stop-db-instance --db-instance-identifier ${id} --region ap-southeast-1 --profile dev
done

Upvotes: 3

Related Questions