- Newest
- Most votes
- Most comments
Hello,
You can leverage the AWS SDK for Go API Reference for STS here [1] and there's also a Dev Guide Github which shows how to configure client endpoints [2].
An example code has also been provided in reference to Dynamo DB for Customizing service client endpoints in the above Dev Guide on Github ->
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
if service == dynamodb.ServiceID && region == "us-west-2" {
return aws.Endpoint{
PartitionID: "aws",
URL: "https://test.us-west-2.amazonaws.com",
SigningRegion: "us-west-2",
}, nil
}
// returning EndpointNotFoundError will allow the service to fallback to it's default resolution
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithEndpointResolverWithOptions(customResolver))
In the context of STS, you need to specify sts.ServiceID, and to use an sts specific URL / your own custom URL like below -
func main() {
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
if service == sts.ServiceID && region == "us-east-1" {
return aws.Endpoint{
PartitionID: "aws",
URL: "https://sts.us-east-1.amazonaws.com",
SigningRegion: "us-east-1",
}, nil
}
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("us-east-1"))
if err != nil {
panic(fmt.Sprintf("Error configuring AWS: %s", err))
}
// test with an api call: //
simpleTokenService := sts.NewFromConfig(cfg)
output, err := simpleTokenService.GetCallerIdentity(context.Background(), &sts.GetCallerIdentityInput{})
if err != nil {
panic(fmt.Sprintf("Error configuring AWS: %s", err))
}
fmt.Printf("%v\n", *output.Account)
}
In case if you still have any questions or concerns regarding the SDK, it's usage or issues, then please feel free to reach out to our Dev team directly by pulling an issue on the Github [3] to discuss your use case.
References:
[1] https://docs.aws.amazon.com/sdk-for-go/api/service/sts/
[2] https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/endpoints/
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 6 months ago