From 63f5373d95591537054bb0704d825dcfca2d1a1d Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 5 Dec 2014 19:23:34 -0800 Subject: [PATCH] Fix for Aliasing https://github.com/mitchellh/goamz/blob/master/route53/route53.go#L101 According to Creating Alias Resource Record Sets documentation (http://docs.aws.amazon.com/Route53/latest/APIReference/CreateAliasRRSAPI.html), we do not include the XML element `` when we want to create an alias but the present code inserts this element when the `query` is called by `ChangeResourceRecordSets`. So in case we need to create an alias with load balancer, we need to take out `` element. Kind of dirty but it works. Without this, I keep getting error of `client.ChangeResourceRecordSets error:Request failed, got status code: 400. Response: ` --- route53/route53.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/route53/route53.go b/route53/route53.go index fcf9644f..92d623f6 100644 --- a/route53/route53.go +++ b/route53/route53.go @@ -105,6 +105,18 @@ func (r *Route53) query(method, path string, req, resp interface{}) error { bodyBuf = &newBuf } + // http://docs.aws.amazon.com/Route53/latest/APIReference/CreateAliasRRSAPI.html + if reflect.Indirect(reflect.ValueOf(req)).Type().Name() == "ChangeResourceRecordSetsRequest" { + for _, change := range req.(ChangeResourceRecordSetsRequest).Changes { + if change.Record.AliasTarget != nil { + replace := change.Record.Type + "0" + var newBuf bytes.Buffer + newBuf.WriteString(strings.Replace(bodyBuf.String(), replace, change.Record.Type+"", -1)) + bodyBuf = &newBuf + } + } + } + body = bodyBuf }