only update records and notify if IP has changed
Build and Push Container / build-and-push (push) Successful in 1m19s
Build and Push Container / build-and-push (push) Successful in 1m19s
This commit is contained in:
+27
-2
@@ -36,7 +36,26 @@ def _get_route53_client() -> Route53Client:
|
||||
return boto3.client("route53")
|
||||
|
||||
|
||||
def update_ipv4(hosted_zone_id: str, record: str, public_ipv4: str) -> None:
|
||||
def _get_current_record(hosted_zone_id: str, record: str, record_type: str) -> str | None:
|
||||
client = _get_route53_client()
|
||||
try:
|
||||
response = client.list_resource_record_sets(HostedZoneId=hosted_zone_id)
|
||||
record_normalized = record.rstrip(".")
|
||||
for rrset in response["ResourceRecordSets"]:
|
||||
if rrset["Name"].rstrip(".") == record_normalized and rrset["Type"] == record_type:
|
||||
records = rrset.get("ResourceRecords", [])
|
||||
if records:
|
||||
return records[0]["Value"].rstrip(".")
|
||||
except Exception as e:
|
||||
logger.warning("Failed to get current %s record for %s: %s", record_type, record, e)
|
||||
return None
|
||||
|
||||
|
||||
def update_ipv4(hosted_zone_id: str, record: str, public_ipv4: str) -> bool:
|
||||
current = _get_current_record(hosted_zone_id, record, "A")
|
||||
if current == public_ipv4:
|
||||
logger.info("IPv4 for %s is already %s, no update needed", record, public_ipv4)
|
||||
return False
|
||||
logger.debug("Creating Route53 client for hosted zone %s", hosted_zone_id)
|
||||
client: Route53Client = _get_route53_client()
|
||||
logger.debug("Building ChangeBatch for IPv4: record=%s, ip=%s, ttl=300", record, public_ipv4)
|
||||
@@ -60,12 +79,17 @@ def update_ipv4(hosted_zone_id: str, record: str, public_ipv4: str) -> None:
|
||||
},
|
||||
)
|
||||
logger.info("Successfully updated IPv4 for %s -> %s", record, public_ipv4)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Error updating IPv4 for %s: %s", record, e)
|
||||
raise e
|
||||
|
||||
|
||||
def update_ipv6(hosted_zone_id: str, record: str, public_ipv6: str) -> None:
|
||||
def update_ipv6(hosted_zone_id: str, record: str, public_ipv6: str) -> bool:
|
||||
current = _get_current_record(hosted_zone_id, record, "AAAA")
|
||||
if current == public_ipv6:
|
||||
logger.info("IPv6 for %s is already %s, no update needed", record, public_ipv6)
|
||||
return False
|
||||
logger.debug("Creating Route53 client for hosted zone %s", hosted_zone_id)
|
||||
client = _get_route53_client()
|
||||
logger.debug("Building ChangeBatch for IPv6: record=%s, ip=%s, ttl=300", record, public_ipv6)
|
||||
@@ -89,6 +113,7 @@ def update_ipv6(hosted_zone_id: str, record: str, public_ipv6: str) -> None:
|
||||
},
|
||||
)
|
||||
logger.info("Successfully updated IPv6 for %s -> %s", record, public_ipv6)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Error updating IPv6 for %s: %s", record, e)
|
||||
raise e
|
||||
|
||||
Reference in New Issue
Block a user