I need to stop start multiple EC2 instances and run few command after they start, using bash on the same manage server without needing to ssh.
I know how to start and stop EC2 instances, for example:
start instance:
#! /bin/bash
aws ec2 start-instances --instance-ids i-1a1234
Stop instance:
#! /bin/bash
aws ec2 stop-instances --instance-ids i-1a1234
I figured how to list all EC2 IDs by running:
aws ec2 describe-instances --filters "Name=tag:Name,Values=Test: Instance 1" --query 'Reservations[].Instances[].[InstanceId] --output text
My questions are:
- How can I stop/start multiple EC2 instances?
- How can I grab a specific EC2 instance and run a command to check a service enabled after the instance started?
May be I need to run if
condition to compare the id or tag name with the EC2 instance needed then run the shell command?
I know the logic but please help me with the script details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…