Skip to content

Commit 746ba65

Browse files
authored
feat(aws): Support Custom endpoints (#5942)
#### Summary This PR enables users to configure a single global endpoint that the AWS Plugin will use to sync resources. This enables users to point CloudQuery at 3rd party tools like LocalStack <!--
1 parent 7908fd4 commit 746ba65

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

plugins/source/aws/client/client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ func configureAwsClient(ctx context.Context, logger zerolog.Logger, awsConfig *S
235235
})
236236
}),
237237
}
238+
if awsConfig.EndpointURL != "" {
239+
configFns = append(configFns, config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
240+
func(service, region string, options ...any) (aws.Endpoint, error) {
241+
return aws.Endpoint{
242+
URL: awsConfig.EndpointURL,
243+
HostnameImmutable: aws.ToBool(awsConfig.HostnameImmutable),
244+
PartitionID: awsConfig.PartitionID,
245+
SigningRegion: awsConfig.SigningRegion,
246+
}, nil
247+
})),
248+
)
249+
}
238250

239251
if account.DefaultRegion != "" {
240252
// According to the docs: If multiple WithDefaultRegion calls are made, the last call overrides the previous call values

plugins/source/aws/client/spec.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,31 @@ type AwsOrg struct {
3333
}
3434

3535
type Spec struct {
36-
Regions []string `json:"regions,omitempty"`
37-
Accounts []Account `json:"accounts"`
38-
Organization *AwsOrg `json:"org"`
39-
AWSDebug bool `json:"aws_debug,omitempty"`
40-
MaxRetries *int `json:"max_retries,omitempty"`
41-
MaxBackoff *int `json:"max_backoff,omitempty"`
36+
Regions []string `json:"regions,omitempty"`
37+
Accounts []Account `json:"accounts"`
38+
Organization *AwsOrg `json:"org"`
39+
AWSDebug bool `json:"aws_debug,omitempty"`
40+
MaxRetries *int `json:"max_retries,omitempty"`
41+
MaxBackoff *int `json:"max_backoff,omitempty"`
42+
EndpointURL string `json:"custom_endpoint_url,omitempty"`
43+
HostnameImmutable *bool `json:"custom_endpoint_hostname_immutable,omitempty"`
44+
PartitionID string `json:"custom_endpoint_partition_id,omitempty"`
45+
SigningRegion string `json:"custom_endpoint_signing_region,omitempty"`
4246
}
4347

4448
func (s *Spec) Validate() error {
49+
if s.EndpointURL != "" {
50+
if s.PartitionID == "" {
51+
return fmt.Errorf("custom_endpoint_partition_id is required when custom_endpoint_url is set")
52+
}
53+
if s.SigningRegion == "" {
54+
return fmt.Errorf("custom_endpoint_signing_region is required when custom_endpoint_url is set")
55+
}
56+
if s.HostnameImmutable == nil {
57+
return fmt.Errorf("custom_endpoint_hostname_immutable is required when custom_endpoint_url is set")
58+
}
59+
}
60+
4561
if s.Organization != nil && len(s.Accounts) > 0 {
4662
return errors.New("specifying accounts via both the Accounts and Org properties is not supported. To achieve both, use multiple source configurations")
4763
}

website/pages/docs/plugins/sources/aws/configuration.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,31 @@ This is the (nested) spec used by the AWS source plugin.
100100

101101
If true, will log AWS debug logs, including retries and other request/response metadata
102102

103+
- `max_retries` (int) (default: 10)
104+
105+
Defines the maximum number of times an API request will be retried
106+
107+
- `max_retries` (int) (max_backoff: 30)
108+
109+
Defines the duration between retry attempts
110+
111+
- `custom_endpoint_url` (string) (default: not used)
112+
113+
The base URL endpoint the SDK API clients will use to make API calls to. The SDK will suffix URI path and query elements to this endpoint
114+
115+
- `custom_endpoint_hostname_immutable` (bool) (default: not used)
116+
117+
Specifies if the endpoint's hostname can be modified by the SDK's API client. When using something like LocalStack make sure to set it equal to `True`
118+
119+
- `custom_endpoint_partition_id` (string) (default: not used)
120+
121+
The AWS partition the endpoint belongs to
122+
123+
- `custom_endpoint_signing_region` (string) (default: not used)
124+
125+
The region that should be used for signing the request to the endpoint
126+
127+
103128
## accounts
104129

105130
This is used to specify one or more accounts to extract information from. Note that it should be an array of objects, each with the following fields:

0 commit comments

Comments
 (0)