Created
February 6, 2018 21:45
-
-
Save undeadops/c7e7e6a8d044bbbc985791514027dbe6 to your computer and use it in GitHub Desktop.
aws-sdk-go-v2 - Route53 Create Invalid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go-v2/aws" | |
"github.com/aws/aws-sdk-go-v2/aws/awserr" | |
"github.com/aws/aws-sdk-go-v2/aws/external" | |
"github.com/aws/aws-sdk-go-v2/service/route53" | |
) | |
func main() { | |
cfg, err := external.LoadDefaultAWSConfig() | |
if err != nil { | |
panic("failed to load config, " + err.Error()) | |
} | |
var c []route53.Change | |
change := route53.Change{ // Required | |
Action: route53.ChangeAction("CREATE"), // Required | |
ResourceRecordSet: &route53.ResourceRecordSet{ // Required | |
Name: aws.String("sweethost.sub.example.com."), // Required | |
Type: route53.RRType("CNAME"), // Required | |
ResourceRecords: []route53.ResourceRecord{ | |
{ // Required | |
Value: aws.String("sweetalias.ec2.internal"), // Required | |
}, | |
}, | |
}, | |
} | |
changeErr := change.Validate() | |
if changeErr != nil { | |
fmt.Printf("There was an error in your Change Record: %s\n\n", change) | |
} | |
c = append(c, change) | |
params := &route53.ChangeResourceRecordSetsInput{ | |
ChangeBatch: &route53.ChangeBatch{ | |
Comment: aws.String("CNAME upserts for zone Run by DNS-SYNC"), | |
Changes: c, | |
}, | |
HostedZoneId: aws.String("-------ZONEID-HERE--------"), | |
} | |
svc := route53.New(cfg) | |
parmsErr := params.Validate() | |
if parmsErr != nil { | |
fmt.Printf("There was an error with Validation of route53.ChangeResourceRecordSetsInput") | |
panic(parmsErr) | |
} | |
fmt.Printf("INPUT ---------------------------------------------------\n\n") | |
fmt.Printf("%s\n\n", params.GoString()) | |
fmt.Printf("------------------------------------------------------\n\n") | |
req := svc.ChangeResourceRecordSetsRequest(params) | |
res, err := req.Send() | |
if err != nil { | |
if aerr, ok := err.(awserr.Error); ok { | |
switch aerr.Code() { | |
case route53.ErrCodeNoSuchHostedZone: | |
fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error()) | |
case route53.ErrCodeNoSuchHealthCheck: | |
fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error()) | |
case route53.ErrCodeInvalidChangeBatch: | |
fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error()) | |
case route53.ErrCodeInvalidInput: | |
fmt.Println(route53.ErrCodeInvalidInput, aerr.Error()) | |
case route53.ErrCodePriorRequestNotComplete: | |
fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error()) | |
default: | |
fmt.Println(aerr.Error()) | |
} | |
} else { | |
// Print the error, cast err to awserr.Error to get the Code and | |
// Message from an error. | |
fmt.Println(err.Error()) | |
} | |
} | |
fmt.Printf("Res: %s\n\n", res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TTL is required, Added TTL to code and it works.