gpt4 book ai didi

Golang - 删除 Route53 记录

转载 作者:数据小太阳 更新时间:2023-10-29 03:13:14 24 4
gpt4 key购买 nike

我正在编写一个管理(创建、删除)Route53 记录的 go 程序(使用 AWS Go SDK)。我已成功创建记录,但在删除记录时遇到问题。

这是我到目前为止尝试过的。

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

最佳答案

再次感谢 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)
}

关于Golang - 删除 Route53 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45216035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com