@@ -4,14 +4,14 @@ import (
44 "context"
55 "encoding/json"
66 "fmt"
7- "github.com/grafana/grafana-aws-sdk/pkg/awsauth"
8- "github.com/grafana/grafana-plugin-sdk-go/data"
97 "time"
108
9+ "github.com/grafana/grafana-aws-sdk/pkg/awsauth"
1110 "github.com/grafana/grafana-plugin-sdk-go/backend"
1211 sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
1312 "github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
1413 "github.com/grafana/grafana-plugin-sdk-go/backend/resource"
14+ "github.com/grafana/grafana-plugin-sdk-go/data"
1515 "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
1616 "github.com/grafana/timestream-datasource/pkg/models"
1717
@@ -63,9 +63,33 @@ func NewDatasource(ctx context.Context, s backend.DataSourceInstanceSettings) (i
6363 return nil , backend .DownstreamError (err )
6464 }
6565
66+ var client QueryClient
67+ if settings .Endpoint != "" && settings .Endpoint != "default" {
68+ client = timestreamquery .NewFromConfig (cfg , func (o * timestreamquery.Options ) {
69+ // Why disable Endpoint Discovery when a custom endpoint (e.g., VPC endpoint) is configured?
70+ // - AWS SDK for Go v1: endpoint discovery was OFF by default and only used when endpoint was unset/empty.
71+ // VPC setups worked because DescribeEndpoints was not invoked.
72+ // - AWS SDK for Go v2: endpoint discovery defaults to AUTO. Because Timestream requires discovery,
73+ // the SDK will call DescribeEndpoints before Query. With a custom BaseEndpoint (VPC endpoint),
74+ // DescribeEndpoints is routed through that endpoint, which typically does not implement it,
75+ // resulting in a 404 response.
76+ // - Even forcing discovery through the SDK’s default public resolver can fail if the VPC blocks
77+ // egress to public AWS endpoints.
78+ // To preserve existing customer VPC configurations and avoid breaking changes, we explicitly disable
79+ // endpoint discovery whenever a custom endpoint is provided. Regular operations still use the custom endpoint.
80+ //
81+ // References:
82+ // - v1 behavior (see `EnableEndpointDiscovery` default): https://docs.aws.amazon.com/sdk-for-go/api/aws/
83+ // - v2 EndpointDiscoveryEnableState (AUTO default): https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#EndpointDiscoveryEnableState
84+ o .EndpointDiscovery .EnableEndpointDiscovery = aws .EndpointDiscoveryDisabled
85+ })
86+ } else {
87+ client = timestreamquery .NewFromConfig (cfg )
88+ }
89+
6690 return & timestreamDS {
6791 Settings : settings ,
68- Client : timestreamquery . NewFromConfig ( cfg ) ,
92+ Client : client ,
6993 }, nil
7094}
7195
0 commit comments