Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route53 ListResourceRecordSetsInput doesn't work when HostedZoneId contains "/hostedzone/" #843

Closed
CB-GuangyaoXie opened this issue Oct 20, 2020 · 3 comments · Fixed by #846
Labels
bug This issue is a bug.

Comments

@CB-GuangyaoXie
Copy link

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
Using /hostedzone/xxxxx in HostedZoneId field in ListResourceRecordSetsInput results in unknown error from AWS API.
I know there is this sanitizeHostedZoneIDInput function in the code base but somehow I had to trim /hostedzone/ prefix to avoid the error.

Version of AWS SDK for Go?
v0.27.0

Version of Go (go version)?
go version go1.15.3 darwin/amd64

To Reproduce (observed behavior)

                awscfg, err := config.LoadDefaultConfig()
                svc := route53.NewFromConfig(awscfg)
                zoneID := "/hostedzone/xxxxxxxxxxx"
		result, err := svc.ListResourceRecordSets(
			context.Background(),
			&route53.ListResourceRecordSetsInput{
				HostedZoneId:    aws.String(zoneID),
				StartRecordName: token,
			})

This resulted in error:

2020/10/20 15:32:04 failed because of an API error, Code: UnknownError, Message: UnknownError
panic: operation error Route 53: ListResourceRecordSets, https response error StatusCode: 400, RequestID: , api error UnknownError: UnknownError

It works if I trim the prefix like aws.String(strings.ReplaceAll(zoneID, "/hostedzone/", ""))

Expected behavior
Given ListHostedZones() now returns hostedZoneID in the format of /hostedzone/xxxxx, the module should parse it correctly.

Additional context
Add any other context about the problem here.

@CB-GuangyaoXie CB-GuangyaoXie added the bug This issue is a bug. label Oct 20, 2020
@jasdel
Copy link
Contributor

jasdel commented Oct 20, 2020

Thanks for reporting this issue @CB-GuangyaoXie. It looks like the SDK is generating the customization that removes the /hostedzone/ from the input value into the wrong location within the middleware.

The customization AddSanitizeURLMiddleware should most likely add to the Initialize middleware step not Serialize. As it is it looks like the customization isn't executing until after the operation's input parameters have already been serialized to the request.

@jasdel
Copy link
Contributor

jasdel commented Oct 21, 2020

Looks like I was looking at the wrong about the ordering of the middleware in my comment above.

The following code can reproduce the issue:

package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/route53"
	"github.com/awslabs/smithy-go/middleware"
	smithyhttp "github.com/awslabs/smithy-go/transport/http"
)

func main() {
	cfg, err := config.LoadDefaultConfig()
	if err != nil {
		log.Fatalf("unable to load config, %v", err)
	}

	client := route53.NewFromConfig(cfg, func(o *route53.Options) {
		o.HTTPClient = smithyhttp.WrapLogClient(logger{}, aws.NewBuildableHTTPClient(), true)
	})

	token := "blah"
	zoneID := "/hostedzone/xxxxxxxxxxx"
	_, err = client.ListResourceRecordSets(context.Background(), &route53.ListResourceRecordSetsInput{
		HostedZoneId:    &zoneID,
		StartRecordName: &token,
	}, func(o *route53.Options) {
		o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {
			log.Println(stack.String())
			return nil
		})
	})
	if err != nil {
		log.Fatalf("request failed, %v", err)
	}
}

type logger struct{}

func (logger) Logf(format string, args ...interface{}) {
	log.Printf(format, args...)
}

This results in the following HTTP request and SDK error:

2020/10/20 16:50:04 Request
GET /2013-04-01/hostedzone/hostedzone%2Fxxxxxxxxxxx/rrset?name=blah HTTP/0.0
Host: route53.amazonaws.com
Amz-Sdk-Invocation-Id: e5a896cf-6f8e-4bee-a159-5129d88bf0ef
Amz-Sdk-Request: attempt=1; max=3
Authorization: <auth>
User-Agent: aws-sdk-go/0.27.0 GOOS/darwin GOARCH/amd64 GO/go1.15.1 route53
X-Amz-Date: 20201020T235004Z

2020/10/20 16:50:04 Response
HTTP/1.1 400 Bad Request
Connection: close
Date: Tue, 20 Oct 2020 23:50:04 GMT
Content-Length: 0

With the following error:

2020/10/20 16:50:04 request failed, operation error Route 53: ListResourceRecordSets, https response error StatusCode: 400, RequestID: , api error UnknownError: UnknownError

The operation's middleware stack looks correct.

2020/10/20 16:56:06 ListResourceRecordSets
        Initialize stack step
                RegisterServiceMetadata
                OperationInputValidation
        Serialize stack step
                ResolveEndpoint
                Route53:SanitizeURL
                OperationSerializer
        Build stack step
                RequestInvocationIDMiddleware
                ContentLengthMiddleware
                ComputePayloadSHA256Middleware
                requestUserAgent
        Finalize stack step
                RetryAttemptMiddleware
                MetricsHeaderMiddleware
                SigV4SignHTTPRequestMiddleware
        Deserialize stack step
                errorCloseResponseBodyMiddleware
                closeResponseBodyMiddleware
                AWSResponseErrorWrapperMiddleware
                AWSRequestIDRetrieverMiddleware
                OperationDeserializer
                AttemptClockSkewMiddleware

@jasdel
Copy link
Contributor

jasdel commented Oct 21, 2020

Looks like the issue is that the SDK's customization for the ListResourceRecordSets that trims the /hostedzone/ doesn't function correct if the first slash(/) is present. The SDK's customization should instead find the last slash (/) and drop it and everything before it. Leaving only the ID portion of the hosted zone id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants