Há mais AWS SDK exemplos disponíveis no GitHub repositório AWS Doc SDK Examples
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use ChangeResourceRecordSets
com um CLI
Os exemplos de código a seguir mostram como usar o ChangeResourceRecordSets
.
- CLI
-
- AWS CLI
-
Para criar, atualizar e excluir um conjunto de registros de recurso
O
change-resource-record-sets
comando a seguir cria um conjunto de registros de recursos usando a configuraçãohosted-zone-id
Z1R8UBAEXAMPLE
e a JSON formatada no arquivo: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.jsonPara obter mais informações, consulte POST ChangeResourceRecordSets na Amazon Route 53 API Reference.
A configuração no JSON arquivo depende do tipo de conjunto de registros de recursos que você deseja criar:
BasicWeightedAliasWeighted AliasLatencyLatency AliasFailoverFailover Pseudônimo
Sintaxe básica:
{ "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" }, {...} ] } }, {...} ] }
Sintaxe ponderada:
{ "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" } }, {...} ] }
Sintaxe de 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" } }, {...} ] }
Sintaxe de alias ponderado:
{ "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" } }, {...} ] }
Sintaxe de latência:
{ "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" } }, {...} ] }
Sintaxe de alias de latência:
{ "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" } }, {...} ] }
Sintaxe de 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" } }, {...} ] }
Sintaxe de alias de 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" } }, {...} ] }
-
Para API obter detalhes, consulte ChangeResourceRecordSets
na Referência de AWS CLI Comandos.
-
- PowerShell
-
- Ferramentas para PowerShell
-
Exemplo 1: este exemplo cria um registro A para www.example.com e altera o registro A para test.example.com de 192.0.2.3 a 192.0.2.1. Observe que os valores dos registros do TXT tipo changes devem estar entre aspas duplas. Consulte a documentação do Amazon Route 53 para obter mais detalhes. Você pode usar o Get-R53Change cmdlet para pesquisar para determinar quando as alterações foram concluídas.
$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
Exemplo 2: este exemplo mostra como criar conjuntos de registros de recurso alias. 'Z222222222' é o ID da zona hospedada do Amazon Route 53 na qual você está criando o conjunto de registros de recurso alias. 'exemplo.com' é o ápex da zona para o qual você deseja criar um alias e 'www.exemplo.com' é um subdomínio para o qual você também deseja criar um alias. 'Z1111111111111' é um exemplo de ID de zona hospedada para o balanceador de carga e 'example-load-balancer-1111111111.us-east-1.elb.amazonaws.com' é um exemplo de nome de domínio do balanceador de carga com o qual o Amazon Route 53 responde às consultas de example.com e www.example.com. Consulte a documentação do Amazon Route 53 para obter mais detalhes. Você pode usar o Get-R53Change cmdlet para pesquisar para determinar quando as alterações foram concluídas.
$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
Exemplo 3: este exemplo cria dois registros A para www.example.com. Um quarto das vezes (1/(1+3)), o Amazon Route 53 responde às consultas para www.example.com com os dois valores para o primeiro conjunto de registros de recurso (192.0.2.9 e 192.0.2.10). Três quartos das vezes (3/(1+3)), o Amazon Route 53 responde às consultas para www.example.com com os dois valores para o primeiro conjunto de registros de recurso (192.0.2.11 e 192.0.2.12). Consulte a documentação do Amazon Route 53 para obter mais detalhes. Você pode usar o Get-R53Change cmdlet para pesquisar para determinar quando as alterações foram concluídas.
$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
Exemplo 4: Este exemplo mostra como criar conjuntos de registros de recursos de alias ponderados, supondo que example.com seja o domínio para o qual você deseja criar conjuntos de registros de recursos de alias ponderados. SetIdentifier diferencia os dois conjuntos de registros de recursos de alias ponderados um do outro. Esse elemento é necessário porque os elementos Nome e Tipo têm os mesmos valores para os dois conjuntos de registros de recurso. Z11111111111 e Z333333333333333 são exemplos de zona hospedada para o balanceador de carga especificado pelo valor de. IDs ELB DNSName example-load-balancer-22222222.us-east-1.elb.amazonaws.com e example-load-balancer -4444444444.us-east-1.elb.amazonaws.com são exemplos de domínios do Elastic Load Balancing dos quais o Amazon Route 53 responde a consultas de example.com. Consulte a documentação do Amazon Route 53 para obter mais detalhes. Você pode usar o Get-R53Change cmdlet para pesquisar para determinar quando as alterações foram concluídas.
$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
Exemplo 5: Este exemplo cria dois conjuntos de registros de recursos de alias de latência, um para um balanceador de ELB carga na região Oeste dos EUA (Oregon) (us-west-2) e outro para um balanceador de carga na região Ásia-Pacífico (Cingapura) (ap-southeast-1). Consulte a documentação do Amazon Route 53 para obter mais detalhes. Você pode usar o Get-R53Change cmdlet para pesquisar para determinar quando as alterações foram concluídas.
$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
-
Para API obter detalhes, consulte ChangeResourceRecordSetsem Referência de AWS Tools for PowerShell cmdlet.
-