krz/aws-summary-report

Automated AWS summary reports, straight to your inbox.

clone: git clone https://gitbay.org/krz/aws-summary-report.git

main: sections/route53.py · raw

 1# route53.py
 2import boto3
 3from tabulate import tabulate
 4
 5
 6def get_section(config):
 7    profile = config["aws"].get("profile")
 8    region = config["aws"]["region"]  # Not used by Route53, but kept for consistency
 9
10    session = boto3.Session(profile_name=profile if profile else None)
11    client = session.client("route53")
12
13    health_checks = client.list_health_checks()["HealthChecks"]
14    rows = []
15
16    for hc in health_checks:
17        hc_id = hc["Id"]
18        name = hc.get("HealthCheckConfig", {}).get(
19            "FullyQualifiedDomainName", "Unnamed"
20        )
21        status = client.get_health_check_status(HealthCheckId=hc_id)
22        status_summary = status["HealthCheckObservations"]
23        healthy = all(
24            obs["StatusReport"]["Status"].startswith("Success")
25            for obs in status_summary
26        )
27        state = "HEALTHY" if healthy else "UNHEALTHY"
28        rows.append([name, state])
29
30    if not rows:
31        return "Route 53 Health Checks:\nNo health checks configured."
32
33    table = tabulate(rows, headers=["Domain", "Status"], tablefmt="simple_grid")
34    lines = [
35        "Route 53 Health Checks:",
36        f"[https://{config['aws'].get('region')}.console.aws.amazon.com/route53/v2/healthchecks/home]",
37        table,
38    ]
39
40    return "\n".join(lines)