英文:
Golang - Delete Route53 Record
问题
我正在编写一个Go程序(使用AWS Go SDK),用于管理(创建、删除)Route53记录。我已经成功创建了一条记录,但在删除记录时遇到了问题。
这是我到目前为止尝试过的代码:
func deleteRecord(svc *route53.Route53) {
dnsName := "vikas027.something.net"
request := &route53.ChangeResourceRecordSetsInput{
ChangeBatch: &route53.ChangeBatch{
Changes: []*route53.Change{
{
Action: aws.String("DELETE"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(dnsName),
Type: aws.String("A"),
ResourceRecords: []*route53.ResourceRecord{
{
Value: aws.String(dnsName),
},
},
},
},
},
},
HostedZoneId: aws.String(zoneID),
}
resp, err := svc.ChangeResourceRecordSets(request)
if err != nil {
fmt.Println("Unable to delete DNS Record", err)
}
fmt.Println(resp)
}
上述函数抛出以下错误:
Unable to delete DNS RecordInvalidInput: Invalid request
status code: 400, request id: 0363068b-6d4d-11e7-ab47-cf662178898b
英文:
I am writing a go program (using AWS Go SDK) which manages (creates, deletes) Route53 Records. I have managed to create a record, but I am having issues while deleting those.
This is what I have tried so far.
func deleteRecord(svc *route53.Route53) {
dnsName := "vikas027.something.net"
request := &route53.ChangeResourceRecordSetsInput{
ChangeBatch: &route53.ChangeBatch{
Changes: []*route53.Change{
{
Action: aws.String("DELETE"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(dnsName),
Type: aws.String("A"),
ResourceRecords: []*route53.ResourceRecord{
{
Value: aws.String(dnsName),
},
},
},
},
},
},
HostedZoneId: aws.String(zoneID),
}
resp, err := svc.ChangeResourceRecordSets(request)
if err != nil {
fmt.Println("Unable to delete DNS Record", err)
}
fmt.Println(resp)
}
Above function throws below error.
Unable to delete DNS RecordInvalidInput: Invalid request
status code: 400, request id: 0363068b-6d4d-11e7-ab47-cf662178898b
答案1
得分: 6
再次感谢Imperalix的提示。基本思路是使用创建记录时使用的确切参数。这是我现在用来删除CNAME
记录的方法。
func deleteRecord(svc *route53.Route53) {
dnsName := "vikas027.something.net"
request := &route53.ChangeResourceRecordSetsInput{
ChangeBatch: &route53.ChangeBatch{
Changes: []*route53.Change{
{
Action: aws.String("DELETE"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(dnsName),
Type: aws.String("CNAME"),
ResourceRecords: []*route53.ResourceRecord{
{
Value: aws.String(AliasName),
},
},
TTL: aws.Int64(ttl),
Weight: aws.Int64(weight),
SetIdentifier: aws.String(setIdentifier),
},
},
},
},
HostedZoneId: aws.String(zoneID),
}
resp, err := svc.ChangeResourceRecordSets(request)
if err != nil {
fmt.Println("Unable to delete DNS Record", err)
}
fmt.Println(resp)
}
英文:
Thanks again Imperalix for the hint. The basic idea is to use the exact parameters which were used to create the record. This is what is now working for me to delete CNAME
records.
func deleteRecord(svc *route53.Route53) {
dnsName := "vikas027.something.net"
request := &route53.ChangeResourceRecordSetsInput{
ChangeBatch: &route53.ChangeBatch{
Changes: []*route53.Change{
{
Action: aws.String("DELETE"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(dnsName),
Type: aws.String("CNAME"),
ResourceRecords: []*route53.ResourceRecord{
{
Value: aws.String(AliasName),
},
},
TTL: aws.Int64(ttl),
Weight: aws.Int64(weight),
SetIdentifier: aws.String(setIdentifier),
},
},
},
},
HostedZoneId: aws.String(zoneID),
}
resp, err := svc.ChangeResourceRecordSets(request)
if err != nil {
fmt.Println("Unable to delete DNS Record", err)
}
fmt.Println(resp)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论