bp-check/services/asg.py

42 lines
1.2 KiB
Python
Raw Normal View History

2024-08-05 02:30:34 +00:00
from models import RuleCheckResult
import boto3
2024-08-08 07:46:20 +00:00
client = boto3.client("autoscaling")
2024-08-05 02:30:34 +00:00
def autoscaling_group_elb_healthcheck_required():
2024-08-08 07:46:20 +00:00
compliant_resources = []
non_compliant_resources = []
asgs = client.describe_auto_scaling_groups()["AutoScalingGroups"]
for asg in asgs:
if asg.get("HealthCheckType", {}) == "ELB":
compliant_resources.append(asg["AutoScalingGroupARN"])
else:
non_compliant_resources.append(asg["AutoScalingGroupARN"])
2024-08-05 02:30:34 +00:00
return RuleCheckResult(
2024-08-08 07:46:20 +00:00
passed=not non_compliant_resources,
compliant_resources=compliant_resources,
non_compliant_resources=non_compliant_resources,
2024-08-05 02:30:34 +00:00
)
def autoscaling_multiple_az():
2024-08-08 07:46:20 +00:00
compliant_resources = []
non_compliant_resources = []
asgs = client.describe_auto_scaling_groups()["AutoScalingGroups"]
for asg in asgs:
if len(asg.get("AvailabilityZones", 0)) > 1:
compliant_resources.append(asg["AutoScalingGroupARN"])
else:
non_compliant_resources.append(asg["AutoScalingGroupARN"])
2024-08-05 02:30:34 +00:00
return RuleCheckResult(
2024-08-08 07:46:20 +00:00
passed=not non_compliant_resources,
compliant_resources=compliant_resources,
non_compliant_resources=non_compliant_resources,
2024-08-05 02:30:34 +00:00
)