In release[v1.6.0][1]of the[AWS SDK for Go][2],we added Regions and Endpoints metadata to the SDK. This feature enables you to easily enumeratethe metadata and discover Regions, Services, and Endpoints. You can find this feature in the[github.com/aws/aws-sdk-go/aws/endpoints][3]package.
Theendpointspackage provides a simple interface toget a service’s endpoint URL and enumerate the Region metadata. The metadata is grouped into partitions. Each partition is a group of AWS Regions such as AWS Standard, AWS China, and AWS GovCloud (US).
### Resolving Endpoints
The SDK automatically uses theendpoints.DefaultResolverfunction when setting the SDK’s default configuration. You can resolve endpoints yourself by calling theEndpointFormethods in theendpointspackage.
If you need to add custom endpoint resolution logic to your code, you can implement theendpoints.Resolverinterface, and set the value to aws.Config.EndpointResolver. This is helpful when you want to provide custom endpoint logic that the SDK will use for resolving service endpoints.
The following example creates a Session that is configured so that[Amazon S3][4]service clients are constructed with a custom endpoint.
Go
```
s3CustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
Thereturn value of the endpoints.DefaultResolverfunction can be cast to the endpoints.EnumPartitionsinterface. This will give you access to the slice of partitions that the SDK will use, and can help you enumerate over partition information for each partition.
Go
```
// Iterate through all partitions printing each partition's ID.
In addition to the list of partitions, theendpointspackage also includes a getter function for each partition group. These utility functions enable you to enumerate a specific partition without having to cast and enumerateover all the default resolver’s partitions.
Go
```
partition := endpoints.AwsPartition()
region := partition.Regions()[endpoints.UsWest2RegionID]
fmt.Println("Services in region:", region.ID())
for id, _ := range region.Services() {
fmt.Println(id)
}
```
Once you have aRegionorServicevalue, you can callResolveEndpointon it. This provides a filtered view of thePartitionwhen resolving endpoints.
Check out the AWS SDK for Go repo for[more examples][5]. Let us know in the comments what you think of theendpointspackage.