Skip to content

Instantly share code, notes, and snippets.

@charlesrc019
Created December 12, 2024 23:30
Show Gist options
  • Save charlesrc019/ca4541d885bafa0d0a993dcfcaeefc0e to your computer and use it in GitHub Desktop.
Save charlesrc019/ca4541d885bafa0d0a993dcfcaeefc0e to your computer and use it in GitHub Desktop.
server_sync_route53_via_api.ps1
# Fetch the public IPv4 address from the metadata service.
$ipUrl = "http://checkip.amazonaws.com/"
$publicIp = Invoke-RestMethod -Uri $ipUrl
if (-not $publicIp) {
Write-Error "Failed to retrieve the public IP address."
exit 1
}
Write-Output "Public IP Address: $publicIp"
#$publicIp = "2.2.2.2"
# Create payload.
$payload = @{
service = "Route53"
action = "upsert"
items = @("desktop.example.co>$publicIp")
}
$json = $payload | ConvertTo-Json
$json = $json.Replace('\n','').Replace('\u003e', '>')
# Update Route53.
try {
$response = Invoke-RestMethod -Method Post -Uri "https://api.example.co/aws" -Body $json -ContentType "application/json"
} catch {
Write-Error -Message $_
}
# Output the response
Write-Output $response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment