Skip to content

Commit

Permalink
Add resolver to handle custom endpoints
Browse files Browse the repository at this point in the history
Currently, setting the AWS_EC2_ENDPOINT environment variable
overwrites the STS endpoint as well. This patch adds a custom
resolver to only set a custom endpoint on EC2 service.
  • Loading branch information
bertinatto committed Sep 22, 2022
1 parent c515a75 commit 98da3a7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cloud/cloud.go
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -248,7 +249,16 @@ func newEC2Cloud(region string, awsSdkDebugLog bool) (Cloud, error) {

endpoint := os.Getenv("AWS_EC2_ENDPOINT")
if endpoint != "" {
awsConfig.Endpoint = aws.String(endpoint)
customResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == endpoints.Ec2ServiceID {
return endpoints.ResolvedEndpoint{
URL: endpoint,
SigningRegion: region,
}, nil
}
return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
}
awsConfig.EndpointResolver = endpoints.ResolverFunc(customResolver)
}

if awsSdkDebugLog {
Expand Down

0 comments on commit 98da3a7

Please sign in to comment.