-
Notifications
You must be signed in to change notification settings - Fork 725
Description
Acknowledgements
- I have searched (https://github.com/aws/aws-sdk/issues?q=is%3Aissue) for past instances of this issue
- I have verified all of my SDK modules are up-to-date (you can perform a bulk update with
go get -u github.com/aws/aws-sdk-go-v2/...
)
Describe the bug
The ResolveEndpoint methods on EndpointResolverV2 types claim to return an error if an endpoint is not found:
aws-sdk-go-v2/service/ec2/endpoints.go
Lines 291 to 298 in 5a6b2c0
// 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:
aws-sdk-go-v2/internal/endpoints/awsrulesfn/partition.go
Lines 32 to 56 in 5a6b2c0
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