|
@ -41,6 +41,10 @@ instanceType = 't2.micro' |
|
|
# keyName = 'srieger-pub' |
|
|
# keyName = 'srieger-pub' |
|
|
keyName = 'vockey' |
|
|
keyName = 'vockey' |
|
|
|
|
|
|
|
|
|
|
|
# see, e.g., AWS Academy Lab readme, or "aws iam list-instance-profiles | grep InstanceProfileName" |
|
|
|
|
|
# for roles see: "aws iam list-roles | grep RoleName" |
|
|
|
|
|
iamRole = 'LabInstanceProfile' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################################ |
|
|
################################################################################################ |
|
|
# |
|
|
# |
|
@ -85,7 +89,7 @@ subnet_id3 = ec2Client.describe_subnets( |
|
|
])['Subnets'][0]['SubnetId'] |
|
|
])['Subnets'][0]['SubnetId'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Deleting auto scaling group...") |
|
|
|
|
|
|
|
|
print("Deleting old auto scaling group...") |
|
|
print("------------------------------------") |
|
|
print("------------------------------------") |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
@ -93,7 +97,7 @@ try: |
|
|
except ClientError as e: |
|
|
except ClientError as e: |
|
|
print(e) |
|
|
print(e) |
|
|
|
|
|
|
|
|
print("Deleting launch configuration...") |
|
|
|
|
|
|
|
|
print("Deleting old launch configuration...") |
|
|
print("------------------------------------") |
|
|
print("------------------------------------") |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
@ -118,7 +122,7 @@ for reservation in reservations: |
|
|
instanceToTerminate.wait_until_terminated() |
|
|
instanceToTerminate.wait_until_terminated() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Deleting load balancer and deps...") |
|
|
|
|
|
|
|
|
print("Deleting old load balancer and deps...") |
|
|
print("------------------------------------") |
|
|
print("------------------------------------") |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
@ -275,7 +279,7 @@ print("------------------------------------") |
|
|
|
|
|
|
|
|
response = asClient.create_launch_configuration( |
|
|
response = asClient.create_launch_configuration( |
|
|
#IamInstanceProfile='my-iam-role', |
|
|
#IamInstanceProfile='my-iam-role', |
|
|
IamInstanceProfile='EMR_AutoScaling_DefaultRole ', |
|
|
|
|
|
|
|
|
IamInstanceProfile=iamRole, |
|
|
ImageId=imageId, |
|
|
ImageId=imageId, |
|
|
InstanceType=instanceType, |
|
|
InstanceType=instanceType, |
|
|
LaunchConfigurationName='tug-of-war-asg-launchconfig', |
|
|
LaunchConfigurationName='tug-of-war-asg-launchconfig', |
|
@ -367,6 +371,9 @@ print(loadbalancer_arn) |
|
|
print(targetgroup_arn) |
|
|
print(targetgroup_arn) |
|
|
print('app/tug-of-war-asg-loadbalancer/'+str(loadbalancer_arn).split('/')[3]+'/targetgroup/tug-of-war-asg-targetgroup/'+str(targetgroup_arn).split('/')[2]) |
|
|
print('app/tug-of-war-asg-loadbalancer/'+str(loadbalancer_arn).split('/')[3]+'/targetgroup/tug-of-war-asg-targetgroup/'+str(targetgroup_arn).split('/')[2]) |
|
|
|
|
|
|
|
|
|
|
|
print('If target group is not found, creation was delayed in AWS Academy lab, need to add a check that target group is' |
|
|
|
|
|
'existing before executing the next lines in the future... If the error occurs, rerun script...') |
|
|
|
|
|
|
|
|
response = asClient.put_scaling_policy( |
|
|
response = asClient.put_scaling_policy( |
|
|
AutoScalingGroupName='tug-of-war-asg-autoscalinggroup', |
|
|
AutoScalingGroupName='tug-of-war-asg-autoscalinggroup', |
|
|
PolicyName='tug-of-war-asg-scalingpolicy', |
|
|
PolicyName='tug-of-war-asg-scalingpolicy', |
|
@ -381,4 +388,15 @@ response = asClient.put_scaling_policy( |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
print('Load Balancer should be reachable at: ' + loadbalancer_dns) |
|
|
|
|
|
|
|
|
print('Load Balancer should be reachable at: http://' + loadbalancer_dns) |
|
|
|
|
|
|
|
|
|
|
|
print('As always, you need to wait some time, until load balancer is provisioned, instances are healthy (cloud-init ' |
|
|
|
|
|
'did its job as specified in the launch configuration). ') |
|
|
|
|
|
|
|
|
|
|
|
print('You can use "aws elbv2 ..." commands or the web console to examine the current state. Take a look at Load' |
|
|
|
|
|
'Balancer, Target Group, Auto Scaling Group and esp. Monitoring of the Load Balancer and related Cloud Watch' |
|
|
|
|
|
'alarms.') |
|
|
|
|
|
|
|
|
|
|
|
print('If you "pull" a lot of clouds in the game, generating a lot of requests, you will see the alarm being fired and' |
|
|
|
|
|
'further instances started (scale-out) (involves some clicking for about three minutes). After 15 min of idling,' |
|
|
|
|
|
'instances will automatically be stopped (scale-in).') |