Gunakan ChangeResourceRecordSets dengan CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan ChangeResourceRecordSets dengan CLI

Contoh kode berikut menunjukkan cara menggunakanChangeResourceRecordSets.

CLI
AWS CLI

Untuk membuat, memperbarui, atau menghapus kumpulan catatan sumber daya

change-resource-record-setsPerintah berikut membuat catatan sumber daya yang ditetapkan menggunakan hosted-zone-id Z1R8UBAEXAMPLE dan konfigurasi JSON -format dalam file: C:\awscli\route53\change-resource-record-sets.json

aws route53 change-resource-record-sets --hosted-zone-id Z1R8UBAEXAMPLE --change-batch file://C:\awscli\route53\change-resource-record-sets.json

Untuk informasi selengkapnya, lihat POST ChangeResourceRecordSets di APIReferensi Amazon Route 53.

Konfigurasi dalam JSON file tergantung pada jenis kumpulan catatan sumber daya yang ingin Anda buat:

BasicWeightedAliasWeighted AliasLatencyLatency AliasFailoverFailover Alias

Sintaks dasar:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ] } }, {...} ] }

Sintaks tertimbang:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Weight": value between 0 and 255, "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ], "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

Sintaks Alias:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

Sintaks Alias Tertimbang:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Weight": value between 0 and 255, "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

Sintaks Latensi:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Region": "Amazon EC2 region name", "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ], "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

Sintaks Alias Latensi:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Region": "Amazon EC2 region name", "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

Sintaks Failover:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Failover": "PRIMARY" | "SECONDARY", "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ], "HealthCheckId": "ID of an Amazon Route 53 health check" } }, {...} ] }

Sintaks Alias Failover:

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Failover": "PRIMARY" | "SECONDARY", "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }
PowerShell
Alat untuk PowerShell

Contoh 1: Contoh ini membuat catatan A untuk www.example.com dan mengubah catatan A untuk test.example.com dari 192.0.2.3 menjadi 192.0.2.1. Perhatikan bahwa nilai untuk perubahan TXT -type record harus dalam tanda kutip ganda. Lihat dokumentasi Amazon Route 53 untuk detail selengkapnya. Anda dapat menggunakan Get-R53Change cmdlet untuk melakukan polling untuk menentukan kapan perubahan selesai.

$change1 = New-Object Amazon.Route53.Model.Change $change1.Action = "CREATE" $change1.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change1.ResourceRecordSet.Name = "www.example.com" $change1.ResourceRecordSet.Type = "TXT" $change1.ResourceRecordSet.TTL = 600 $change1.ResourceRecordSet.ResourceRecords.Add(@{Value="item 1 item 2 item 3"}) $change2 = New-Object Amazon.Route53.Model.Change $change2.Action = "DELETE" $change2.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change2.ResourceRecordSet.Name = "test.example.com" $change2.ResourceRecordSet.Type = "A" $change2.ResourceRecordSet.TTL = 600 $change2.ResourceRecordSet.ResourceRecords.Add(@{Value="192.0.2.3"}) $change3 = New-Object Amazon.Route53.Model.Change $change3.Action = "CREATE" $change3.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change3.ResourceRecordSet.Name = "test.example.com" $change3.ResourceRecordSet.Type = "A" $change3.ResourceRecordSet.TTL = 600 $change3.ResourceRecordSet.ResourceRecords.Add(@{Value="192.0.2.1"}) $params = @{ HostedZoneId="Z1PA6795UKMFR9" ChangeBatch_Comment="This change batch creates a TXT record for www.example.com. and changes the A record for test.example.com. from 192.0.2.3 to 192.0.2.1." ChangeBatch_Change=$change1,$change2,$change3 } Edit-R53ResourceRecordSet @params

Contoh 2: Contoh ini menunjukkan cara membuat kumpulan catatan sumber daya alias. 'Z222222222' adalah ID dari zona yang dihosting Amazon Route 53 tempat Anda membuat kumpulan catatan sumber daya alias. 'example.com' adalah puncak zona tempat Anda ingin membuat alias dan 'www.example.com' adalah subdomain yang Anda juga ingin membuat alias. 'Z11111111111' adalah contoh ID zona yang dihosting untuk penyeimbang beban dan 'example-load-balancer-1111111111.us-east-1.elb.amazonaws.com' adalah contoh nama domain penyeimbang beban yang digunakan Amazon Route 53 untuk menanggapi kueri untuk example.com dan www.example.com. Lihat dokumentasi Amazon Route 53 untuk detail selengkapnya. Anda dapat menggunakan Get-R53Change cmdlet untuk melakukan polling untuk menentukan kapan perubahan selesai.

$change1 = New-Object Amazon.Route53.Model.Change $change1.Action = "CREATE" $change1.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change1.ResourceRecordSet.Name = "example.com" $change1.ResourceRecordSet.Type = "A" $change1.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget $change1.ResourceRecordSet.AliasTarget.HostedZoneId = "Z1111111111111" $change1.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-1111111111.us-east-1.elb.amazonaws.com." $change1.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $true $change2 = New-Object Amazon.Route53.Model.Change $change2.Action = "CREATE" $change2.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change1.ResourceRecordSet.Name = "www.example.com" $change1.ResourceRecordSet.Type = "A" $change1.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget $change1.ResourceRecordSet.AliasTarget.HostedZoneId = "Z1111111111111" $change1.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-1111111111.us-east-1.elb.amazonaws.com." $change1.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $false $params = @{ HostedZoneId="Z222222222" ChangeBatch_Comment="This change batch creates two alias resource record sets, one for the zone apex, example.com, and one for www.example.com, that both point to example-load-balancer-1111111111.us-east-1.elb.amazonaws.com." ChangeBatch_Change=$change1,$change2 } Edit-R53ResourceRecordSet @params

Contoh 3: Contoh ini membuat dua catatan A untuk www.example.com. Seperempat dari waktu (1/ (1+3)), Amazon Route 53 menanggapi kueri untuk www.example.com dengan dua nilai untuk kumpulan catatan sumber daya pertama (192.0.2.9 dan 192.0.2.10). Tiga perempat waktu (3/ (1+3)) Amazon Route 53 menanggapi kueri untuk www.example.com dengan dua nilai untuk kumpulan catatan sumber daya kedua (192.0.2.11 dan 192.0.2.12). Lihat dokumentasi Amazon Route 53 untuk detail selengkapnya. Anda dapat menggunakan Get-R53Change cmdlet untuk melakukan polling untuk menentukan kapan perubahan selesai.

$change1 = New-Object Amazon.Route53.Model.Change $change1.Action = "CREATE" $change1.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change1.ResourceRecordSet.Name = "www.example.com" $change1.ResourceRecordSet.Type = "A" $change1.ResourceRecordSet.SetIdentifier = "Rack 2, Positions 4 and 5" $change1.ResourceRecordSet.Weight = 1 $change1.ResourceRecordSet.TTL = 600 $change1.ResourceRecordSet.ResourceRecords.Add(@{Value="192.0.2.9"}) $change1.ResourceRecordSet.ResourceRecords.Add(@{Value="192.0.2.10"}) $change2 = New-Object Amazon.Route53.Model.Change $change2.Action = "CREATE" $change2.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change2.ResourceRecordSet.Name = "www.example.com" $change2.ResourceRecordSet.Type = "A" $change2.ResourceRecordSet.SetIdentifier = "Rack 5, Positions 1 and 2" $change2.ResourceRecordSet.Weight = 3 $change2.ResourceRecordSet.TTL = 600 $change2.ResourceRecordSet.ResourceRecords.Add(@{Value="192.0.2.11"}) $change2.ResourceRecordSet.ResourceRecords.Add(@{Value="192.0.2.12"}) $params = @{ HostedZoneId="Z1PA6795UKMFR9" ChangeBatch_Comment="This change creates two weighted resource record sets, each of which has two values." ChangeBatch_Change=$change1,$change2 } Edit-R53ResourceRecordSet @params

Contoh 4: Contoh ini menunjukkan cara membuat kumpulan catatan sumber daya alias tertimbang dengan asumsi bahwa example.com adalah domain yang ingin Anda buat kumpulan catatan sumber daya alias tertimbang. SetIdentifier membedakan dua set catatan sumber daya alias tertimbang satu sama lain. Elemen ini diperlukan karena elemen Nama dan Jenis memiliki nilai yang sama untuk kedua kumpulan catatan sumber daya. Z1111111111111 dan Z3333333333333 adalah contoh zona host untuk penyeimbang beban yang ditentukan oleh nilai. IDs ELB DNSName example-load-balancer-2222222222.us-east-1.elb.amazonaws.com dan example-load-balancer -4444444444.us-east-1.elb.amazonaws.com adalah contoh domain Elastic Load Balancing dari mana Amazon Route 53 menanggapi kueri untuk example.com. Lihat dokumentasi Amazon Route 53 untuk detail selengkapnya. Anda dapat menggunakan Get-R53Change cmdlet untuk melakukan polling untuk menentukan kapan perubahan selesai.

$change1 = New-Object Amazon.Route53.Model.Change $change1.Action = "CREATE" $change1.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change1.ResourceRecordSet.Name = "example.com" $change1.ResourceRecordSet.Type = "A" $change1.ResourceRecordSet.SetIdentifier = "1" $change1.ResourceRecordSet.Weight = 3 $change1.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget $change1.ResourceRecordSet.AliasTarget.HostedZoneId = "Z1111111111111" $change1.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-2222222222.us-east-1.elb.amazonaws.com." $change1.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $true $change2 = New-Object Amazon.Route53.Model.Change $change2.Action = "CREATE" $change2.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change2.ResourceRecordSet.Name = "example.com" $change2.ResourceRecordSet.Type = "A" $change2.ResourceRecordSet.SetIdentifier = "2" $change2.ResourceRecordSet.Weight = 1 $change2.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget $change2.ResourceRecordSet.AliasTarget.HostedZoneId = "Z3333333333333" $change2.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-4444444444.us-east-1.elb.amazonaws.com." $change2.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $false $params = @{ HostedZoneId="Z5555555555" ChangeBatch_Comment="This change batch creates two weighted alias resource record sets. Amazon Route 53 responds to queries for example.com with the first ELB domain 3/4ths of the times and the second one 1/4th of the time." ChangeBatch_Change=$change1,$change2 } Edit-R53ResourceRecordSet @params

Contoh 5: Contoh ini membuat dua set catatan sumber daya alias latensi, satu untuk penyeimbang ELB beban di wilayah AS Barat (Oregon) (us-west-2), dan satu lagi untuk penyeimbang beban di wilayah Asia Pasifik (Singapura) (ap-southeast-1). Lihat dokumentasi Amazon Route 53 untuk detail selengkapnya. Anda dapat menggunakan Get-R53Change cmdlet untuk melakukan polling untuk menentukan kapan perubahan selesai.

$change1 = New-Object Amazon.Route53.Model.Change $change1.Action = "CREATE" $change1.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change1.ResourceRecordSet.Name = "example.com" $change1.ResourceRecordSet.Type = "A" $change1.ResourceRecordSet.SetIdentifier = "Oregon load balancer 1" $change1.ResourceRecordSet.Region = us-west-2 $change1.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget $change1.ResourceRecordSet.AliasTarget.HostedZoneId = "Z1111111111111" $change1.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-2222222222.us-west-2.elb.amazonaws.com" $change1.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $true $change2 = New-Object Amazon.Route53.Model.Change $change2.Action = "CREATE" $change2.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet $change2.ResourceRecordSet.Name = "example.com" $change2.ResourceRecordSet.Type = "A" $change2.ResourceRecordSet.SetIdentifier = "Singapore load balancer 1" $change2.ResourceRecordSet.Region = ap-southeast-1 $change2.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget $change2.ResourceRecordSet.AliasTarget.HostedZoneId = "Z2222222222222" $change2.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-1111111111.ap-southeast-1.elb.amazonaws.com" $change2.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $true $params = @{ HostedZoneId="Z5555555555" ChangeBatch_Comment="This change batch creates two latency resource record sets, one for the US West (Oregon) region and one for the Asia Pacific (Singapore) region." ChangeBatch_Change=$change1,$change2 } Edit-R53ResourceRecordSet @params