Created
March 18, 2020 18:20
-
-
Save Jonty/f6edd5566e123d1910daed751b4c315c to your computer and use it in GitHub Desktop.
Grab autoscaling settings for all elastic beanstalk applications and environments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
eb = boto3.client("elasticbeanstalk") | |
asg = boto3.client("autoscaling") | |
response = eb.describe_environments() | |
instances = 0 | |
for env in response["Environments"]: | |
resources = eb.describe_environment_resources( | |
EnvironmentName=env["EnvironmentName"] | |
) | |
groups = asg.describe_auto_scaling_groups( | |
AutoScalingGroupNames=[ | |
a["Name"] for a in resources["EnvironmentResources"]["AutoScalingGroups"] | |
] | |
) | |
ms = "1 - NOT AUTOSCALING!" | |
ds = 1 | |
gs = groups["AutoScalingGroups"] | |
if len(gs) > 0: | |
ms = groups["AutoScalingGroups"][0]["MinSize"] | |
ds = groups["AutoScalingGroups"][0]["DesiredCapacity"] | |
instances += ds | |
if ms != ds: | |
print( | |
env["ApplicationName"], env["EnvironmentName"], "Min:", ms, "Current:", ds | |
) | |
print("Total vm's: ", instances) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment