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

API Gateway request dropping stage from endpoint #1191

Closed
3 tasks done
laverboy opened this issue Mar 23, 2021 · 8 comments · Fixed by #1199
Closed
3 tasks done

API Gateway request dropping stage from endpoint #1191

laverboy opened this issue Mar 23, 2021 · 8 comments · Fixed by #1199
Labels
bug This issue is a bug.

Comments

@laverboy
Copy link

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

Describe the bug
When using a required custom resolver with apigatewaymanagmentapi service it appears that the stage is being dropped from the url used.

Version of AWS SDK for Go?
v1.2.1

Version of Go (go version)?
1.15

To Reproduce (observed behavior)
We are using the following custom resolver

customResolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
		if service == apigatewaymanagementapi.ServiceID && region == "eu-west-1" {
			return aws.Endpoint{
				PartitionID:       "aws",
				URL:                 "https://xxxxxx.execute-api.eu-west-1.amazonaws.com/LATEST",
				SigningRegion:     "eu-west-1",
				HostnameImmutable: true,
				Source:            aws.EndpointSourceCustom,
			}, nil
		}
		return aws.Endpoint{}, fmt.Errorf("unknown endpoint requested")
	})

	cfg, err := config.LoadDefaultConfig(context.Background(), config.WithEndpointResolver(customResolver), config.WithClientLogMode(aws.LogRetries|aws.LogRequest))

And we are making the request like so:

_, err := wsc.client.GetConnection(ctx, &apigatewaymanagementapi.GetConnectionInput{
		ConnectionId: aws.String("xxxxxxxxxx=x"),
	})

See logs below

Expected behavior
We are expecting to get a successful response from the api.

Additional context
We are seeing the following error logs, it appears that the url no longer includes LATEST which is the name of our stage

SDK 2021/03/23 15:44:54 DEBUG Request
--
GET /@connections/cpV6NdyODoECInw%3D HTTP/1.1
Host: xxxxxxxx.execute-api.eu-west-1.amazonaws.com
User-Agent: aws-sdk-go-v2/1.2.1
Amz-Sdk-Invocation-Id: eacfb162-7c3c-4903-a210-e37c3ff632ba
Amz-Sdk-Request: attempt=1; max=3
Authorization: <REDACTED>
X-Amz-Date: 20210323T154454Z
X-Amz-Security-Token: <REDACTED>
X-Amz-User-Agent: aws-sdk-go-v2/1.2.1 os/linux lang/go/1.16.2 md/GOOS/linux md/GOARCH/amd64 exec-env/AWS_Lambda_go1.x
Accept-Encoding: gzip
SDK 2021/03/23 15:44:54 DEBUG request failed with unretryable error https response error StatusCode: 403, RequestID: 99ba811c-47ae-4c62-bece-9b3128218d5f, ForbiddenException:

The documentation here https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html clearly shows that the stage is a required element of the url. If we miss it out from cli usage we see the same error as above.

It looks this is a regression since v0.24, as our code using that version works fine.

@laverboy laverboy added the bug This issue is a bug. label Mar 23, 2021
@jasdel
Copy link
Contributor

jasdel commented Mar 29, 2021

Thanks for reporting this issue @laverboy. It looks like the SDK's behavior of parsing the endpoint URL is stripping out the path. The SDK parsing of endpoint URL to not drop the query Path will need to be investigated to fix this issue.

@youjinp
Copy link

youjinp commented Mar 30, 2021

I just stumbled across this issue too, is there a workaround for the mean time?

youjinp pushed a commit to youjinp/aws-sdk-go-v2 that referenced this issue Mar 30, 2021
@youjinp
Copy link

youjinp commented Mar 30, 2021

found the bug in service/apigatewaymanagementapi/serializers.go

func (m *awsRestjson1_serializeOpGetConnection) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) {
        ...
	opPath, opQuery := httpbinding.SplitURI("/@connections/{ConnectionId}")

        // SHOULD BE request.URL.Path + opPath
        // otherwise this will override the current path (containing the stage) 
	request.URL.Path = opPath 

        ...
}

Now, if only I knew how this was file auto generated...

@jasdel
Copy link
Contributor

jasdel commented Mar 30, 2021

Thanks for the additional information. We created PR #1199 to address this issue. We're researching if this is the correct fix for the SDK, or if alternative solution is needed. In the mean time you can Update your application to depend on this change to see if it addresses the issue you're running into.

go get -d github.com/aws/smithy-go@v1.2.1-0.20210330205207-0917d08124fa
go get -d github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi@v1.1.4-0.20210330212709-261f02169228

Updated the above command with the latest version of the hashes.

@youjinp
Copy link

youjinp commented Mar 30, 2021

It's working now! 👍

@jasdel
Copy link
Contributor

jasdel commented Mar 30, 2021

Thanks for the update @youjinp, let us know if you have any additional issues, or feedback. We'll get this fixed merged in and released once we've reviewed it.

@laverboy
Copy link
Author

Can I ask how long that might take - thanks

jasdel added a commit to aws/smithy-go that referenced this issue Mar 31, 2021
Updates the Smithy SDK client httpbinding serializers to use the JoinPath and JoinRawQuery utilities to ensure paths and query are joined correctly.

Related to # aws/aws-sdk-go-v2#1191
jasdel added a commit that referenced this issue Mar 31, 2021
Fixes the API clients to not ignore the resolved endpoint's URL Path and RawQuery parameters. Instead of ignoring the values the SDK will append the operation's modeled Path and Query String.

Fixes #1191

Depends on aws/smithy-go#280
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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
3 participants