Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

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

Closed
2 tasks done
rifelpet opened this issue Mar 28, 2024 · 1 comment
Closed
2 tasks done

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

rifelpet opened this issue Mar 28, 2024 · 1 comment
Assignees
Labels
bug This issue is a bug.

Comments

@rifelpet
Copy link

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

@rifelpet rifelpet added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 28, 2024
@RanVaknin
Copy link
Contributor

Hi @rifelpet ,

Thanks for reaching out.

What you are describing is the intended behavior. The SDK treats region identifiers as opaque strings and does not strip or validate them. When it encounters an unknown or invalid region string, instead of throwing an error, it defaults to using the AWS partition’s endpoint. This behavior ensures that the SDK remains forward-compatible, allowing new regions to "just work" as they become available without needing to update to the SDK.

Thanks,
Ran~

@RanVaknin RanVaknin self-assigned this Mar 28, 2024
@RanVaknin RanVaknin removed the needs-triage This issue or PR still needs to be triaged. label Mar 28, 2024
@aws aws locked and limited conversation to collaborators Mar 28, 2024
@RanVaknin RanVaknin converted this issue into discussion #2586 Mar 28, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants