rjurney / Agile_Data_Code_2

Code for Agile Data Science 2.0, O'Reilly 2017, Second Edition
http://bit.ly/agile_data_science
MIT License
456 stars 306 forks source link

ec2.sh is tagging ALL instances in the Account/Region #77

Closed jmcdonald24 closed 5 years ago

jmcdonald24 commented 6 years ago

The ec2.sh script is tagging all instances in the region (even pre-existing, unrelated instances) not just the newly created one.

rjurney commented 5 years ago

Thanks, very sorry for this. Resolved by https://github.com/rjurney/Agile_Data_Code_2/commit/1077843a1e3ff33530f47e1b982f937ed3aafef4

echo "Now we will tag this ec2 instance and name it 'agile_data_science_ec2' ..." | tee -a $LOG_FILE
INSTANCE_ID=`aws ec2 describe-instances | jq -c ".Reservations[] | select(.ReservationId | contains(\"$RESERVATION_ID\"))| .Instances[0].InstanceId" | tr -d '"'`

if [ ! -z "$INSTANCE_ID" ] # Only run tag if INSTANCE_ID is defined
then
  echo "Got instance id \"$INSTANCE_ID\" ... tagging it ..."
  aws ec2 create-tags --resources $INSTANCE_ID --tags Key=Name,Value=agile_data_science_ec2
  echo "" | tee -a $LOG_FILE
else
  echo "Got no instance id! Exiting!"
  exit 1
fi