@@ -134,13 +134,13 @@ func New(ctx context.Context, config *Config) (*AWS, error) {
134134 }
135135 config .AccountID = aws .ToString (identity .Account )
136136
137- // Create per-region clients
138- awsClientPerRegion , err := newRegionClientMap (ctx , ac , regions , config .Profile , config .RoleARN )
137+ pricingConfig , err := createAWSConfig (ctx , "us-east-1" , config .Profile , config .RoleARN )
139138 if err != nil {
140139 return nil , err
141140 }
142141
143- pricingConfig , err := createAWSConfig (ctx , "us-east-1" , config .Profile , config .RoleARN )
142+ // Create per-region clients
143+ awsClientPerRegion , err := newRegionClientMap (ctx , ac , pricingConfig , regions , config .Profile , config .RoleARN )
144144 if err != nil {
145145 return nil , err
146146 }
@@ -152,6 +152,7 @@ func New(ctx context.Context, config *Config) (*AWS, error) {
152152func newWithDependencies (ctx context.Context , config * Config , awsClient client.Client , regionClients map [string ]client.Client , regions []types.Region , awsConfig aws.Config , pricingConfig aws.Config ) (* AWS , error ) {
153153 var collectors []provider.Collector
154154 logger := config .Logger .With ("provider" , subsystem )
155+ pricingAPI := awsPricing .NewFromConfig (pricingConfig )
155156
156157 for _ , service := range config .Services {
157158 service = strings .ToUpper (service )
@@ -184,17 +185,8 @@ func newWithDependencies(ctx context.Context, config *Config, awsClient client.C
184185 }
185186 collectors = append (collectors , collector )
186187 case serviceRDS :
187- // pricing API for RDS client needs to use always the same region
188- // as for RDS, the pricing data is only available in the us-east-1
189- pricingConfig , err := createAWSConfig (ctx , "us-east-1" , config .Profile , config .RoleARN )
190- if err != nil {
191- logger .LogAttrs (ctx , slog .LevelError , "Error creating collector" ,
192- slog .String ("service" , service ),
193- slog .String ("message" , err .Error ()))
194- continue
195- }
196188 awsRDSClient := client .NewAWSClient (client.Config {
197- PricingService : awsPricing . NewFromConfig ( pricingConfig ) ,
189+ PricingService : pricingAPI ,
198190 RDSService : rds .NewFromConfig (awsConfig ),
199191 })
200192 collector , err := rdsCollector .New (ctx , & rdsCollector.Config {
@@ -226,17 +218,8 @@ func newWithDependencies(ctx context.Context, config *Config, awsClient client.C
226218 }
227219 collectors = append (collectors , collector )
228220 case serviceELB :
229- // pricing API for ELB client needs to use always the same region
230- // as the pricing data is only available in us-east-1
231- elbPricingConfig , err := createAWSConfig (ctx , "us-east-1" , config .Profile , config .RoleARN )
232- if err != nil {
233- logger .LogAttrs (ctx , slog .LevelError , "Error creating collector" ,
234- slog .String ("service" , service ),
235- slog .String ("message" , err .Error ()))
236- continue
237- }
238221 awsELBPricingClient := client .NewAWSClient (client.Config {
239- PricingService : awsPricing . NewFromConfig ( elbPricingConfig ) ,
222+ PricingService : pricingAPI ,
240223 })
241224 collector , err := elb .New (ctx , & elb.Config {
242225 Regions : regions ,
@@ -253,17 +236,8 @@ func newWithDependencies(ctx context.Context, config *Config, awsClient client.C
253236 }
254237 collectors = append (collectors , collector )
255238 case serviceVPC :
256- // pricing API for VPC client needs to use always the same region
257- // as for VPC, the pricing data is only available in the us-east-1
258- pricingConfig , err := createAWSConfig (ctx , "us-east-1" , config .Profile , config .RoleARN )
259- if err != nil {
260- logger .LogAttrs (ctx , slog .LevelError , "Error creating collector" ,
261- slog .String ("service" , service ),
262- slog .String ("message" , err .Error ()))
263- continue
264- }
265239 awsVPCClient := client .NewAWSClient (client.Config {
266- PricingService : awsPricing . NewFromConfig ( pricingConfig ) ,
240+ PricingService : pricingAPI ,
267241 EC2Service : ec2 .NewFromConfig (pricingConfig ),
268242 })
269243 collector , err := awsvpc .New (ctx , & awsvpc.Config {
@@ -281,7 +255,7 @@ func newWithDependencies(ctx context.Context, config *Config, awsClient client.C
281255 collectors = append (collectors , collector )
282256 case serviceMSK :
283257 awsMSKClient := client .NewAWSClient (client.Config {
284- PricingService : awsPricing . NewFromConfig ( pricingConfig ) ,
258+ PricingService : pricingAPI ,
285259 })
286260 collector , err := mskCollector .New (ctx , & mskCollector.Config {
287261 Regions : regions ,
@@ -301,10 +275,8 @@ func newWithDependencies(ctx context.Context, config *Config, awsClient client.C
301275 // Note: this pins the *endpoint*, not the queried region — the collector still
302276 // fetches prices per configured region via a regionCode filter. See
303277 // pkg/aws/bedrock.go newPriceFetcher().
304- bedrockPricingConfig := awsConfig .Copy ()
305- bedrockPricingConfig .Region = "us-east-1"
306278 awsBedrockClient := client .NewAWSClient (client.Config {
307- PricingService : awsPricing . NewFromConfig ( bedrockPricingConfig ) ,
279+ PricingService : pricingAPI ,
308280 })
309281 collector , err := bedrock .New (ctx , & bedrock.Config {
310282 Regions : regions ,
@@ -410,7 +382,7 @@ func filterExcludedRegions(regions []types.Region, excludeList []string) []types
410382 return filtered
411383}
412384
413- func newRegionClientMap (ctx context.Context , globalConfig aws.Config , regions []types.Region , profile string , roleARN string ) (map [string ]client.Client , error ) {
385+ func newRegionClientMap (ctx context.Context , globalConfig aws.Config , pricingConfig aws. Config , regions []types.Region , profile string , roleARN string ) (map [string ]client.Client , error ) {
414386 awsClientPerRegion := make (map [string ]client.Client )
415387 for _ , region := range regions {
416388 ac , err := createAWSConfig (ctx , * region .RegionName , profile , roleARN )
@@ -419,7 +391,7 @@ func newRegionClientMap(ctx context.Context, globalConfig aws.Config, regions []
419391 }
420392 awsClientPerRegion [* region .RegionName ] = client .NewAWSClient (
421393 client.Config {
422- PricingService : awsPricing .NewFromConfig (globalConfig ),
394+ PricingService : awsPricing .NewFromConfig (pricingConfig ),
423395 EC2Service : ec2 .NewFromConfig (ac ),
424396 BillingService : costexplorer .NewFromConfig (globalConfig ),
425397 RDSService : rds .NewFromConfig (ac ),
0 commit comments