Speaking of Cloud Environment where auto
- scaling, self-healing servers have replaced the more conservative way of
scaling – We can’t have classic manual way of DNS management. I.e. Each new instance launched by auto
scaling group should assign itself a human-readable hostname. In these cases Instance
itself should be equipped enough to add its corresponding entry under Route 53.
We can make use of Route53 and PowerShell to impalement this automation from Windows
machine.
What Is Route 53?
Route 53 is a complete DNS solution provided by Amazon that
lets you control every aspect of the name resolution process for your domain. You
choose a registrar to reserve your domain, as common practice
they often be managing all the DNSs for your domain. But if you are
looking for more granular control over this Route 53 is one of the services you
should be interested in. A details description of Route 53 is beyond the scope
of this article, but you can check at AWS Route 53
Automation Script
I have wrapped the whole script into a function.We have used PowerShell V3 , consider that as prerequisite.Having Amazon cmdlets loaded should be done before expecting it to work.Pointers related to it's functioning :
I have wrapped the whole script into a function.We have used PowerShell V3 , consider that as prerequisite.Having Amazon cmdlets loaded should be done before expecting it to work.Pointers related to it's functioning :
- Execution of this script will only materialize given working pair of Secret Key & Access Key
- It validates the Record type with values mentioned under ValidateSet
- If wait is specified, the function will wait until AWS confirms that the change is in sync. To be more specific it verifies whether entry has been propagated under specified Zone. By default i have kept it as false
- If you have mentioned wait as true, waitinterval specifies the interval in milliseconds between each polling
- Every parameter can be overridden why calling this function
Function Create-AwsRoute53Record
{
[CmdletBinding(SupportsShouldProcess=$true)]
Param (
[String]$AccessKeyID="****************",
[String]$SecretAccessKeyID="*****************",
[String]$Region="us-east-1",
[Parameter(Mandatory=$true)] $Zone,
[ValidateSet("A", "SOA", "PTR", "MX", "CNAME","TXT","SRV","SPF","AAAA","NS")]
[String]$RecordType,
[Parameter(Mandatory=$true)]
[String]$Name,
[Parameter(Mandatory=$true)]$Value,
$TTL,
$wait = $false,
[int]$waitinterval = 1000
)
Process
{
Set-AWSCredentials -AccessKey $InfoObject.AccessKey -SecretKey $InfoObject.SecretKey
Set-DefaultAWSRegion -Region $region
$zoneEntry = (Get-R53HostedZones) | ? {$_.Name -eq "$($Zone)."}
$hostedZone = $zoneEntry.Id
if (@($zoneEntry).count -eq 1) {
$Record = new-object Amazon.Route53.Model.ResourceRecord
$record.Value = $Value
#add the trailing dot
if (!($Name.EndsWith(".")) -and $Name)
{$Name += "."}
$ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
$ResourceRecordSet.Type = $RecordType
$ResourceRecordSet.ResourceRecords = $Record
$ResourceRecordSet.Name = $Name
$ResourceRecordSet.TTL = $TTL
$change = New-Object Amazon.Route53.Model.Change
$change.Action = "Create"
$change.ResourceRecordSet = $ResourceRecordSet
$Changes = (New-Object -TypeName System.Collections.ArrayList($null))
$Changes.Add($Change)
Try
{
$result = Edit-R53ResourceRecordSet -ChangeBatch_Changes $Changes -HostedZoneId $hostedZone
}
Catch [system.Exception]
{
Write-error $error[0]
}
if ($result)
{
if ($wait)
{
#Keep polling the result until it is no longer pending
Do
{
#get change status
if ($SecondPoll)
{Start-Sleep -Milliseconds $waitinterval}
$status=Get-R53Change -Id $result.Id
$SecondPoll = $true
Write-verbose "Waiting for changes to sync. Current status is $($status.Status.Value)"
}
Until ($status.Status.Value -eq "INSYNC")
}
$Status
}
}
}
}
{
[CmdletBinding(SupportsShouldProcess=$true)]
Param (
[String]$AccessKeyID="****************",
[String]$SecretAccessKeyID="*****************",
[String]$Region="us-east-1",
[Parameter(Mandatory=$true)] $Zone,
[ValidateSet("A", "SOA", "PTR", "MX", "CNAME","TXT","SRV","SPF","AAAA","NS")]
[String]$RecordType,
[Parameter(Mandatory=$true)]
[String]$Name,
[Parameter(Mandatory=$true)]$Value,
$TTL,
$wait = $false,
[int]$waitinterval = 1000
)
Process
{
Set-AWSCredentials -AccessKey $InfoObject.AccessKey -SecretKey $InfoObject.SecretKey
Set-DefaultAWSRegion -Region $region
$zoneEntry = (Get-R53HostedZones) | ? {$_.Name -eq "$($Zone)."}
$hostedZone = $zoneEntry.Id
if (@($zoneEntry).count -eq 1) {
$Record = new-object Amazon.Route53.Model.ResourceRecord
$record.Value = $Value
#add the trailing dot
if (!($Name.EndsWith(".")) -and $Name)
{$Name += "."}
$ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
$ResourceRecordSet.Type = $RecordType
$ResourceRecordSet.ResourceRecords = $Record
$ResourceRecordSet.Name = $Name
$ResourceRecordSet.TTL = $TTL
$change = New-Object Amazon.Route53.Model.Change
$change.Action = "Create"
$change.ResourceRecordSet = $ResourceRecordSet
$Changes = (New-Object -TypeName System.Collections.ArrayList($null))
$Changes.Add($Change)
Try
{
$result = Edit-R53ResourceRecordSet -ChangeBatch_Changes $Changes -HostedZoneId $hostedZone
}
Catch [system.Exception]
{
Write-error $error[0]
}
if ($result)
{
if ($wait)
{
#Keep polling the result until it is no longer pending
Do
{
#get change status
if ($SecondPoll)
{Start-Sleep -Milliseconds $waitinterval}
$status=Get-R53Change -Id $result.Id
$SecondPoll = $true
Write-verbose "Waiting for changes to sync. Current status is $($status.Status.Value)"
}
Until ($status.Status.Value -eq "INSYNC")
}
$Status
}
}
}
}
Script Execution
Below we have a sample execution which captures the Public IP of AWS instance , and subsequently add it to specified Zone as A Name record Type.
# Change the values as per your specification i.e Zone , Name , RecordType and TTL. Wait is enabled to provide added control.
$LocalIP = Invoke-RestMethod -Uri http://169.254.169.254/latest/meta-data/local-ipv4 -Method Get
$LocalIP=$LocalIP.Trim()
Create-AwsRoute53Record -Zone xyz.com -RecordType A -Name testing.xyz.com -Value $LocalIP -TTL 500 -wait $true
thanks for providing such a simple information with program AWS Online Training Bangalore
ReplyDeleteinformation is nice but please update daily very useful to us
ReplyDeleteAws Online Training
amasya
ReplyDeletesinop
çorum
sakarya
van
Q05
yozgat
ReplyDeletesivas
bayburt
van
uşak
A3MC
görüntülü
ReplyDeleteucretli show
DH7İ
maraş evden eve nakliyat
ReplyDeletemaraş evden eve nakliyat
izmir evden eve nakliyat
konya evden eve nakliyat
erzurum evden eve nakliyat
VZCNW
C7535
ReplyDeleteUrfa Evden Eve Nakliyat
Hakkari Lojistik
Sinop Şehir İçi Nakliyat
Rize Şehir İçi Nakliyat
Yenimahalle Parke Ustası
Ankara Şehirler Arası Nakliyat
Bursa Parça Eşya Taşıma
Malatya Lojistik
Urfa Şehirler Arası Nakliyat
CCF99
ReplyDeleteNevşehir Şehir İçi Nakliyat
Van Evden Eve Nakliyat
Adana Evden Eve Nakliyat
Bartın Lojistik
Uşak Parça Eşya Taşıma
Ankara Asansör Tamiri
Ankara Şehirler Arası Nakliyat
Çerkezköy Evden Eve Nakliyat
Bingöl Şehirler Arası Nakliyat
D792B
ReplyDeleteBingöl Evden Eve Nakliyat
Bursa Evden Eve Nakliyat
Yalova Şehirler Arası Nakliyat
Sinop Parça Eşya Taşıma
Muş Şehirler Arası Nakliyat
Van Parça Eşya Taşıma
Erzurum Şehirler Arası Nakliyat
Çankırı Lojistik
Casper Coin Hangi Borsada
0CE9C
ReplyDeleteEdirne Lojistik
Burdur Şehir İçi Nakliyat
Edirne Parça Eşya Taşıma
Kırıkkale Parça Eşya Taşıma
Silivri Fayans Ustası
Aydın Lojistik
Batman Evden Eve Nakliyat
Manisa Lojistik
Ağrı Parça Eşya Taşıma
4B99C
ReplyDeleteprimobolan for sale
testosterone propionat
https://steroidsbuy.net/steroids/
Kastamonu Evden Eve Nakliyat
Artvin Evden Eve Nakliyat
Isparta Evden Eve Nakliyat
Hakkari Evden Eve Nakliyat
buy trenbolone enanthate
Kırklareli Evden Eve Nakliyat
C2631
ReplyDeletereferanskodunedir.com.tr
370C4
ReplyDeletemuhabbet sohbet
sinop görüntülü sohbet
kütahya telefonda canlı sohbet
ücretsiz sohbet sitesi
kilis canlı sohbet ücretsiz
adıyaman ucretsiz sohbet
adana rastgele görüntülü sohbet ücretsiz
bayburt tamamen ücretsiz sohbet siteleri
karabük yabancı görüntülü sohbet siteleri
29799
ReplyDeletemanisa rastgele görüntülü sohbet
hakkari tamamen ücretsiz sohbet siteleri
sohbet sitesi
erzurum görüntülü sohbet ücretsiz
ağrı en iyi ücretsiz sohbet siteleri
seslı sohbet sıtelerı
tunceli en iyi görüntülü sohbet uygulaması
sivas canlı sohbet sitesi
kütahya mobil sohbet chat
7A91C
ReplyDeleteamasya kadınlarla rastgele sohbet
mersin bedava sohbet chat odaları
parasız görüntülü sohbet uygulamaları
niğde sesli sohbet mobil
trabzon bedava sohbet chat odaları
görüntülü sohbet kızlarla
tekirdağ rastgele görüntülü sohbet ücretsiz
kars sohbet
muş sesli sohbet sesli chat
512C3
ReplyDeletemanisa parasız sohbet
parasız sohbet
ankara en iyi rastgele görüntülü sohbet
Bayburt Mobil Sohbet Sitesi
canlı sohbet uygulamaları
rastgele görüntülü sohbet ücretsiz
Sakarya Sesli Sohbet Odası
Batman Sohbet Chat
Gümüşhane Ücretsiz Sohbet Sitesi
DA2FE
ReplyDeleteBitcoin Nasıl Alınır
Snapchat Takipçi Satın Al
Snapchat Takipçi Hilesi
Xcn Coin Hangi Borsada
Coin Oynama
Twitch Takipçi Satın Al
Ort Coin Hangi Borsada
Coin Çıkarma Siteleri
Mexc Borsası Kimin
18C97
ReplyDeletePeriscope Takipçi Satın Al
Görüntülü Sohbet
Gate io Borsası Güvenilir mi
Twitter Beğeni Satın Al
Coin Para Kazanma
Binance Referans Kodu
Parasız Görüntülü Sohbet
Binance Hangi Ülkenin
Binance Referans Kodu
31171
ReplyDeleteKangal
Mazgirt
Ayrancı
İmamoğlu
Şirvan
Beşikdüzü
Derince
Söğütlü
Selim
شركة صيانة افران بالاحساء vRhTSD1t5y
ReplyDelete