Skip to content

EndpointResolverV2 doesn't error if an endpoint is not found #2584

@rifelpet

Description

@rifelpet

Acknowledgements

Describe the bug

The ResolveEndpoint methods on EndpointResolverV2 types claim to return an error if an endpoint is not found:

// EndpointResolverV2 provides the interface for resolving service endpoints.
type EndpointResolverV2 interface {
// ResolveEndpoint attempts to resolve the endpoint with the provided options,
// returning the endpoint if found. Otherwise an error is returned.
ResolveEndpoint(ctx context.Context, params EndpointParameters) (
smithyendpoints.Endpoint, error,
)
}

However this is not the case.

Expected Behavior

An error to be returned if an endpoint is not found

Current Behavior

An endpoint is returned that includes the invalid EndpointParameters values.

Reproduction Steps

While go playground wont run the code in the browser, this can be ran locally to demonstrate that no error is returned:

https://go.dev/play/p/DaFEJcapgvl

	resolver := ec2.NewDefaultEndpointResolverV2()
	endpoint, err := resolver.ResolveEndpoint(ctx, ec2.EndpointParameters{Region: aws.String("us-abcdefg-1")})
go run main.go
{URI:{Scheme:https Opaque: User: Host:sts.us-abcdefg-1.amazonaws.com Path: RawPath: OmitHost:false ForceQuery:false RawQuery: Fragment: RawFragment:} Headers:map[] Properties:{values:map[]}}, <nil>

Possible Solution

The resolver calls this internal function:

func getPartition(partitions []Partition, region string) *PartitionConfig {
for _, partition := range partitions {
if v, ok := partition.Regions[region]; ok {
p := mergeOverrides(partition.DefaultConfig, v)
return &p
}
}
for _, partition := range partitions {
regionRegex := regexp.MustCompile(partition.RegionRegex)
if regionRegex.MatchString(region) {
v := partition.DefaultConfig
return &v
}
}
for _, partition := range partitions {
if partition.ID == defaultPartition {
v := partition.DefaultConfig
return &v
}
}
return nil
}

which falls back to the default aws partition, causing the incorrect endpoint to use the aws partition's DNS suffix.

Additional Information/Context

Being able to determine whether a region is included in the SDK or not is useful to shortcut having to make an API call to ec2.DescribeRegions.

This was possible in the v1 SDK: https://go.dev/play/p/9rp92s-CpXe

AWS Go SDK V2 Module Versions Used

	github.com/aws/aws-sdk-go v1.51.6
	github.com/aws/aws-sdk-go-v2 v1.26.0
	github.com/aws/aws-sdk-go-v2/config v1.27.9
	github.com/aws/aws-sdk-go-v2/credentials v1.17.9
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0
	github.com/aws/aws-sdk-go-v2/service/ec2 v1.152.0
	github.com/aws/aws-sdk-go-v2/service/kms v1.30.0
	github.com/aws/aws-sdk-go-v2/service/s3 v1.53.0

Compiler and Version used

go version go1.22.1 darwin/arm64

Operating System and version

MacOS 14.4.1

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions