Skip to content

Instantly share code, notes, and snippets.

@Jonty
Created Mar 18, 2020
Embed
What would you like to do?
Grab autoscaling settings for all elastic beanstalk applications and environments
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