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

aws/session: Fix client init not exposing endpoint resolve error #3059

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
### SDK Enhancements

### SDK Bugs
* `aws/session`: Fix client init not exposing endpoint resolve error ([#3059](https://github.com/aws/aws-sdk-go/pull/3059))
* Fixes the SDK API clients not surfacing endpoint resolution errors, when the EndpointResolver is unable to resolve an endpoint for the client and region.
14 changes: 10 additions & 4 deletions aws/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,16 @@ func (s *Session) ClientConfig(service string, cfgs ...*aws.Config) client.Confi

region := aws.StringValue(s.Config.Region)
resolved, err := s.resolveEndpoint(service, region, s.Config)
if err != nil && s.Config.Logger != nil {
s.Config.Logger.Log(fmt.Sprintf(
"ERROR: unable to resolve endpoint for service %q, region %q, err: %v",
service, region, err))
if err != nil {
s.Handlers.Validate.PushBack(func(r *request.Request) {
if len(r.ClientInfo.Endpoint) != 0 {
// Error occurred while resolving endpoint, but the request
// being invoked has had an endpoint specified after the client
// was created.
return
}
r.Error = err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to check if we need to wrap this error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error that will be returned will be a UnknownEndpointError error with

e.g.

UnknownEndpointError: could not resolve endpoint
	partition: "aws", service: "s3", region: "",

})
}

return client.Config{
Expand Down
9 changes: 6 additions & 3 deletions aws/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func TestNew_WithSessionLoadError(t *testing.T) {
os.Setenv("AWS_PROFILE", "assume_role_invalid_source_profile")

logger := bytes.Buffer{}
s := New(&aws.Config{Logger: &mockLogger{&logger}})
s := New(&aws.Config{
Region: aws.String("us-west-2"),
Logger: &mockLogger{&logger},
})

if s == nil {
t.Errorf("expect not nil")
Expand Down Expand Up @@ -178,8 +181,8 @@ func TestNewSession_ResolveEndpointError(t *testing.T) {
t.Errorf("expect %v validation error, got %v", e, a)
}

if e, a := "unable to resolve", logger.Buffer.String(); !strings.Contains(a, e) {
t.Errorf("expect %v logged, got %v", e, a)
if v := logger.Buffer.String(); len(v) != 0 {
t.Errorf("expect nothing logged, got %s", v)
}
}

Expand Down