diff --git a/build_compliance_workstations.sh b/build_compliance_workstations.sh new file mode 100755 index 0000000..a13b5cb --- /dev/null +++ b/build_compliance_workstations.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Builds training instances in EC2 +USAGE="Usage: $0 [number] [name] [department] [contact] [project] [termination-date]" + +AMI_ID=ami-352f0d22 + +NUMHOSTS=$1 +NAME=$2 +DEPT=$3 +CONTACT=$4 +PROJECT=$5 +TERM_DATE=$6 + +INSTANCE_TYPE="t2.small" +KEY_NAME=$AWS_KEYPAIR_NAME + +if [ "$#" -ne 6 ]; then + echo $USAGE + exit 1 +fi + +for host in $(aws ec2 run-instances --image-id $AMI_ID --region us-east-1 --count $NUMHOSTS --instance-type $INSTANCE_TYPE --key-name $KEY_NAME --security-group-ids "sg-a1c3b1db" --subnet-id subnet-46b55431 | jq -r ".Instances|.[].InstanceId"); do + echo "Created instance: $host" + echo "Tagging $host with \"$NAME\"" + aws ec2 create-tags --resources $host --tags "Key=Name,Value=\"$NAME\"" + aws ec2 create-tags --resources $host --tags "Key=X-Dept,Value=\"$DEPT\"" + aws ec2 create-tags --resources $host --tags "Key=X-Contact,Value=\"$CONTACT\"" + aws ec2 create-tags --resources $host --tags "Key=X-Project,Value=\"$PROJECT\"" + aws ec2 create-tags --resources $host --tags "Key=X-Termination-Date,Value=\"$TERM_DATE\"" +done diff --git a/show_running_compliance_instances.sh b/show_running_compliance_instances.sh new file mode 100755 index 0000000..00e57d7 --- /dev/null +++ b/show_running_compliance_instances.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +AMI_ID=ami-352f0d22 + +aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,ImageId,PublicIpAddress,State.Name,Tags[?Key==`Name`].Value | [0]]' --output text | grep running | grep $AMI_ID