Retrieving a partition Id and the default Partition Id

0

Hello, I'm trying to update my code moving from Aws sdk go V1 to V2 and I need to rewrite a function retrieving the partition Id for a given endpoint, The code used to look like this:

	region, err := GetRegion(arguments.GetRegion())
	if err != nil || region == "" {
		return endpoints.AwsPartitionID
	}
	partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region)
	if !ok || partition.ID() == "" {
		return endpoints.AwsPartitionID
	}
	return partition.ID()
}

I achieved the same result using the EndpointResolverdepricated function: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2@v1.22.0/aws#EndpointResolver My problem comes from trying to achieve the same result using the suggested replacement EndpointResolverWithOptions, I'm unsure as to what parameters I need to include for interface and service and or is there any other way to achieve the same result as the initial function?

1 Answer
0

Thank you for reaching out to AWS Premium Support. This is Mihir from Config team to assist you with the case today.

You would like to know what parameters are needed to include for interface and service while using 'EndpointResolverWithOptions'.

I would like to highlight that assistance with application SDK code and code logic involves code support, I would like to take a moment to mention that assistance with code development or debugging is out of scope for AWS Premium Support.

From my research on best effort basis, I was also able to find the below details :

The EndpointResolverWithOptions interface defines a method named ResolveEndpoint that is used to resolve an endpoint for a specific service and region. It includes an optional options parameter that allows you to pass additional configuration or context-specific information when resolving the endpoint.

The ResolveEndpoint method has the following signature: ResolveEndpoint(service, region string, options ...interface{}) (Endpoint, error)

Here's what the parameters mean:

  • service: This is a string that specifies the AWS service for which you want to resolve the endpoint, e.g., "configservice" for AWS Config.
  • region: This is a string that specifies the AWS region where you want to resolve the endpoint, e.g., "us-east-1".
  • options ...interface{}: The options parameter allows you to pass a variable number of additional options or configuration settings as interface{} values. The ... notation indicates that you can pass zero or more options. These options can be used to further customize the endpoint resolution process or provide additional context information.

You can use this options parameter to pass specific configuration or context details, if needed, when resolving the endpoint. The exact type and meaning of the options depend on the specific implementation of the endpoint resolver, and it allows for flexibility in how the endpoint is resolved based on different requirements.

On best effort basis, I am outling the flow for retrieving the partition ID for a given endpoint.

1. Set Up AWS Configuration - Make sure you have your AWS credentials and desired region configured.
2. Create a Custom Resolver -  Custom endpoint resolver by creating a struct that satisfies the `EndpointResolverWithOptions` interface.
3. Implement Custom Endpoint Resolution Logic - This logic should return an `aws.Endpoint` that includes the partition ID.
4. Use the custom resolver to resolve the endpoint.
5. Finally, extract the partition ID using `endpoint.PartitionID()` and return it. The partition ID represents the AWS service's partition to which the endpoint belongs.

Also, find some more links and check if it fulfills your use-case and are helpful in this regard. I would also suggest you to check on github and ask queries there too regarding the same:

  1. https://pkg.go.dev/github.com/aws/aws-sdk-go-v2@v1.22.0/aws#EndpointResolver
  2. https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/endpoints/#migration
  3. https://github.com/aws/aws-sdk-go-v2/discussions

Further, since code support is out of AWS Premium Support, and due to limited expertise with AWS SDK for Go, we can assist you on best effort basis.

Hoping that the above helps.

AWS
Mihir G
answered 5 months ago
  • How come I am unable to call aws.EndpointResolverWithOptions.ResolveEndpoint(service, region) In that case? Why is a custom EndpointResolver necessary? and could you please show an example of how to build one correctly:

    	have (string, string)
    	want ("github.com/aws/aws-sdk-go-v2/aws".EndpointResolverWithOptions, string, string, ...interface{}) ```

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions