Skip to content

Commit

Permalink
add AWS_EC2_ENDPOINT variable for custom endpoint (aws#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jihunseol authored and jdn5126 committed Mar 27, 2023
1 parent c1839cd commit ed8e8e1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/awsutils/awssession/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"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"
)

// Http client timeout env for sessions
Expand Down Expand Up @@ -65,6 +66,21 @@ func New() *session.Session {
},
STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
}

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

sess := session.Must(session.NewSession(&awsCfg))
//injecting session handler info
injectUserAgent(&sess.Handlers)
Expand Down

0 comments on commit ed8e8e1

Please sign in to comment.