diff --git a/aws/service.go b/aws/service.go index e46e39fd2..1e68824c9 100644 --- a/aws/service.go +++ b/aws/service.go @@ -131,12 +131,13 @@ import ( "github.com/aws/aws-sdk-go-v2/service/wafv2" "github.com/aws/aws-sdk-go-v2/service/wellarchitected" "github.com/aws/aws-sdk-go-v2/service/workspaces" + "github.com/aws/smithy-go/logging" + "github.com/hashicorp/go-hclog" "github.com/rs/dnscache" - "golang.org/x/sync/semaphore" - "github.com/turbot/go-kit/helpers" "github.com/turbot/steampipe-plugin-sdk/v5/memoize" "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "golang.org/x/sync/semaphore" amplifyEndpoint "github.com/aws/aws-sdk-go/service/amplify" apigatewayv2Endpoint "github.com/aws/aws-sdk-go/service/apigatewayv2" @@ -1949,6 +1950,12 @@ func getBaseClientForAccountUncached(ctx context.Context, d *plugin.QueryData, h configOptions = append(configOptions, config.WithCredentialsProvider(provider)) } + if plugin.Logger(ctx).GetLevel() <= hclog.Debug { + logger := plugin.Logger(ctx) + configOptions = append(configOptions, config.WithLogger(NewHCLoggerToSmithyLoggerWrapper(&logger))) + configOptions = append(configOptions, config.WithClientLogMode(aws.LogRetries)) + } + plugin.Logger(ctx).Info("getBaseClientForAccountUncached", "connection_name", d.Connection.Name, "status", "loading_config") // NOTE: EC2 metadata service IMDS throttling and retries @@ -2017,6 +2024,19 @@ func getBaseClientForAccountUncached(ctx context.Context, d *plugin.QueryData, h } +// HCLoggerToSmithyLoggerWrapper wraps an hclog Logger in order to pass it as an AWS SDK smithy Logger +type HCLoggerToSmithyLoggerWrapper struct { + hclogger *hclog.Logger +} + +func (logger *HCLoggerToSmithyLoggerWrapper) Logf(classification logging.Classification, format string, v ...interface{}) { + (*logger.hclogger).Debug(fmt.Sprintf(format, v...)) +} + +func NewHCLoggerToSmithyLoggerWrapper(l *hclog.Logger) *HCLoggerToSmithyLoggerWrapper { + return &HCLoggerToSmithyLoggerWrapper{l} +} + // ExponentialJitterBackoff provides backoff delays with jitter based on the // number of attempts. type ExponentialJitterBackoff struct {