creating user specific availability zones

pull/20/head
alok 6 years ago
parent da45cdeef5
commit 4188d098fc
  1. 16
      aws-code/configuration.txt
  2. 20
      aws-code/create_ondemand_instances.py
  3. 13
      aws-code/get_availability_zones.sh

@ -1,8 +1,8 @@
1,us-east-1,virginia-key-benchmark,virginia-security-group,virginia
2,us-east-2,ohio-key-benchmark,ohio-security-group,ohio
3,us-west-1,california-key-benchmark,california-security-group,california
4,us-west-2,oregon-key-benchmark,oregon-security-group,oregon
5,ap-northeast-1,tokyo-key-benchmark,tokyo-security-group,tokyo
6,ap-southeast-1,singapore-key-benchmark,singapore-security-group,singapore
7,eu-central-1,frankfurt-key-benchmark,frankfurt-security-group,frankfurt
8,eu-west-1,ireland-key-benchmark,ireland-security-group,ireland
1,us-east-1,virginia-key-benchmark,virginia-security-group,virginia,ami-b70554c8
2,us-east-2,ohio-key-benchmark,ohio-security-group,ohio,ami-8c122be9
3,us-west-1,california-key-benchmark,california-security-group,california,ami-e0ba5c83
4,us-west-2,oregon-key-benchmark,oregon-security-group,oregon,ami-a9d09ed1
5,ap-northeast-1,tokyo-key-benchmark,tokyo-security-group,tokyo,ami-e99f4896
6,ap-southeast-1,singapore-key-benchmark,singapore-security-group,singapore,ami-05868579
7,eu-central-1,frankfurt-key-benchmark,frankfurt-security-group,frankfurt,ami-7c4f7097
8,eu-west-1,ireland-key-benchmark,ireland-security-group,ireland,ami-466768ac

@ -9,7 +9,7 @@ REGION_KEY = 'region_key'
REGION_SECURITY_GROUP = 'region_security_group'
REGION_HUMAN_NAME = 'region_human_name'
INSTANCE_TYPE = 't2.micro'
AMI = 'ami-a9d09ed1'
REGION_AMI = 'region_ami'
USER_DATA = 'user-data.sh'
IAM_INSTANCE_PROFILE = 'BenchMarkCodeDeployInstanceProfile'
@ -24,16 +24,20 @@ def read_configuration_file(filename):
config[region_num][REGION_KEY] = mylist[2]
config[region_num][REGION_SECURITY_GROUP] = mylist[3]
config[region_num][REGION_HUMAN_NAME] = mylist[4]
config[region_num][REGION_AMI] = mylist[5]
return config
def region_variant(region_name):
return region_name + "a"
def create_custom_json(config,num_instances,region_num,current_session):
print(num_instances)
input_cli = {}
input_cli['MinCount'] = num_instances
input_cli['MaxCount'] = num_instances
input_cli['ImageId'] = 'ami-b70554c8'
input_cli['ImageId'] = config[region_num][REGION_AMI]
input_cli['Placement'] = {}
input_cli['Placement']['AvailabilityZone'] = config[region_num][REGION_NAME] +"a"
input_cli['Placement']['AvailabilityZone'] = region_variant(config[region_num][REGION_NAME])
input_cli['SecurityGroups'] = []
input_cli['SecurityGroups'].append(config[region_num][REGION_SECURITY_GROUP])
input_cli['IamInstanceProfile'] = {}
@ -47,23 +51,25 @@ def create_custom_json(config,num_instances,region_num,current_session):
my_dir = "input_jsons/" + "session-"+ current_session
if not os.path.exists(my_dir):
os.makedirs(my_dir)
cli_input_file = os.path.join(my_dir,config[region_num][REGION_HUMAN_NAME]+".json")
#cli_input_file = os.path.join(my_dir,config[region_num][REGION_HUMAN_NAME]+".json")
cli_input_file = "local.json"
with open(cli_input_file,'w') as g:
json.dump(input_cli,g)
print("INPUT CLI JSON FILE: %s" % cli_input_file)
return cli_input_file
def create_instances(region_list,instances_list,current_session):
def create_instances(config,region_list,instances_list,current_session):
for i in range(len(region_list)):
region_num = region_list[i]
num_instances = int(instances_list[i])
cli_input_file = create_custom_json(config,num_instances,region_num,current_session)
cmd_str = "aws ec2 --region " + config[region_num][REGION_NAME] + " run-instances " + " --cli-input-json " + str(cli_input_file)
print(cmd_str)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='This script helps you start instances across multiple regions')
parser.add_argument('--regions',type=str,dest='regions',default='3',help="Supply a csv list of all regions")
parser.add_argument('--instances', type=str,dest='numInstances',default=1,help='number of shards')
parser.add_argument('--instances', type=str,dest='numInstances',default=1,help='number of instances')
parser.add_argument('--configuration',type=str,dest='config',default='configuration.txt')
args = parser.parse_args()
config = read_configuration_file(args.config)
@ -73,6 +79,6 @@ if __name__ == "__main__":
time_stamp = time.time()
current_session = datetime.datetime.fromtimestamp(time_stamp).strftime('%H-%M-%S-%Y-%m-%d')
print("current session is %s" % current_session)
create_instances(region_list,instances_list,current_session)
create_instances(config,region_list,instances_list,current_session)

@ -0,0 +1,13 @@
echo "Getting list of Availability Zones"
all_regions=$(aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' | sort)
all_az=()
echo $all_regions
while read -r region; do
az_per_region=$(aws ec2 describe-availability-zones --region $region --query 'AvailabilityZones[*].[ZoneName]' --output text | sort)
echo $region $az_per_region
while read -r az; do
all_az+=($az)
done <<< "$az_per_region"
done <<< "$all_regions"
echo $all_az
Loading…
Cancel
Save