Created
December 12, 2024 23:30
-
-
Save charlesrc019/ca4541d885bafa0d0a993dcfcaeefc0e to your computer and use it in GitHub Desktop.
server_sync_route53_via_api.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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