diff --git a/aws/service.go b/aws/service.go index 02e64a2ec..4c394131c 100644 --- a/aws/service.go +++ b/aws/service.go @@ -454,7 +454,6 @@ func CloudWatchLogsService(ctx context.Context, d *plugin.QueryData) (*cloudwatc // CloudTrailService returns the service connection for AWS CloudTrail service func CloudTrailService(ctx context.Context, d *plugin.QueryData, region string) (*cloudtrail.CloudTrail, error) { - if region == "" { return nil, fmt.Errorf("region must be passed CloudTrailService") } @@ -1984,13 +1983,6 @@ func getSessionWithMaxRetries(ctx context.Context, d *plugin.QueryData, region s // get aws config info awsConfig := GetConfig(d.Connection) - // handle custom endpoint url, if any - awsEndpointUrl := os.Getenv("AWS_ENDPOINT_URL") - - if awsConfig.EndpointUrl != nil { - awsEndpointUrl = *awsConfig.EndpointUrl - } - // session default configuration sessionOptions := session.Options{ SharedConfigState: session.SharedConfigEnable, @@ -1998,10 +1990,22 @@ func getSessionWithMaxRetries(ctx context.Context, d *plugin.QueryData, region s Region: ®ion, MaxRetries: aws.Int(maxRetries), Retryer: NewConnectionErrRetryer(maxRetries, minRetryDelay, ctx), - Endpoint: aws.String(awsEndpointUrl), }, } + // handle custom endpoint URL, if any + var awsEndpointUrl string + + awsEndpointUrl = os.Getenv("AWS_ENDPOINT_URL") + + if awsConfig.EndpointUrl != nil { + awsEndpointUrl = *awsConfig.EndpointUrl + } + + if awsEndpointUrl != "" { + sessionOptions.Config.Endpoint = aws.String(awsEndpointUrl) + } + if awsConfig.Profile != nil { sessionOptions.Profile = *awsConfig.Profile } diff --git a/config/aws.spc b/config/aws.spc index 6f840d9d6..5c4bb4144 100644 --- a/config/aws.spc +++ b/config/aws.spc @@ -29,9 +29,8 @@ connection "aws" { # By default, common not found error codes are ignored and will still be ignored even if this argument is not set. #ignore_error_codes = ["AccessDenied", "AccessDeniedException", "NotAuthorized", "UnauthorizedOperation", "UnrecognizedClientException", "AuthorizationError"] - # Specifies the URL to send the AWS request to. In order to make Steampipe to work with Localstack - # it will be required to provide custom url that Steampipe will use: - # 1. The `AWS_ENDPOINT_URL` environment variable - # 2. The endpoint url specified for the particular connection + # Specify the endpoint URL used when making requests to AWS services. + # If not set, the default AWS generated endpoint will be used. + # Can also be set with the AWS_ENDPOINT_URL environment variable. #endpoint_url = "http://localhost:4566" } diff --git a/docs/index.md b/docs/index.md index 6afe53734..d6b1bccab 100644 --- a/docs/index.md +++ b/docs/index.md @@ -97,10 +97,16 @@ connection "aws" { # List of additional AWS error codes to ignore for all queries. # By default, common not found error codes are ignored and will still be ignored even if this argument is not set. #ignore_error_codes = ["AccessDenied", "AccessDeniedException", "NotAuthorized", "UnauthorizedOperation", "UnrecognizedClientException", "AuthorizationError"] + + # Specify the endpoint URL used when making requests to AWS services. + # If not set, the default AWS generated endpoint will be used. + # Can also be set with the AWS_ENDPOINT_URL environment variable. + #endpoint_url = "http://localhost:4566" } ``` - `access_key` - (Optional) AWS access key ID. Can also be set with the `AWS_ACCESS_KEY_ID` environment variable. +- `endpoint_url` - (Optional) The endpoint URL used when making requests to AWS services. If not set, the default AWS generated endpoint will be used. Can also be set with the `AWS_ENDPOINT_URL` environment variable. - `ignore_error_codes` - (Optional) List of additional AWS error codes to ignore for all queries. By default, common not found error codes are ignored and will still be ignored even if this argument is not set. - `max_error_retry_attempts` - (Optional) The maximum number of attempts (including the initial call) Steampipe will make for failing API calls. Can also be set with the `AWS_MAX_ATTEMPTS` environment variable. Defaults to 9 and must be greater than or equal to 1. - `min_error_retry_delay` - (Optional) The minimum retry delay in milliseconds after which retries will be performed. This delay is also used as a base value when calculating the exponential backoff retry times. Defaults to 25ms and must be greater than or equal to 1ms.