From fb0bf02aa5fc844490ea0c12d2c89deb4876beed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:34:17 +0200 Subject: [PATCH 01/12] feat: fetch DynamoDB costs for RCUs and WCUs --- providers/aws/dynamodb/tables.go | 62 +++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 284c5b262..14e719fc0 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -7,16 +7,54 @@ import ( log "github.com/sirupsen/logrus" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/dynamodb" + "github.com/aws/aws-sdk-go-v2/service/pricing" + "github.com/aws/aws-sdk-go-v2/service/pricing/types" "github.com/aws/aws-sdk-go-v2/service/sts" + awsUtils "github.com/tailwarden/komiser/providers/aws/utils" + // "github.com/tailwarden/komiser/utils" . "github.com/tailwarden/komiser/models" . "github.com/tailwarden/komiser/providers" ) +func int64PtrToFloat64(i *int64) float64 { + if i == nil { + return 0.0 // or any default value you prefer + } + return float64(*i) +} + + func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { resources := make([]Resource, 0) var config dynamodb.ListTablesInput dynamodbClient := dynamodb.NewFromConfig(*client.AWSClient) + pricingClient := pricing.NewFromConfig(*client.AWSClient) + + pricingOutput, err := pricingClient.GetProducts(ctx, &pricing.GetProductsInput{ + ServiceCode: aws.String("AmazonDynamoDB"), + Filters: []types.Filter{ + { + Field: aws.String("regionCode"), + Value: aws.String(client.AWSClient.Region), + Type: types.FilterTypeTermMatch, + }, + }, + }) + + if err != nil { + log.Errorf("ERROR: Couldn't fetch pricing info for AWS Lambda: %v", err) + return resources, err + } + + priceMap, err := awsUtils.GetPriceMap(pricingOutput, "group") + if err != nil { + log.Errorf("ERROR: Failed to calculate cost per month: %v", err) + return resources, err + } + + output, err := dynamodbClient.ListTables(ctx, &config) if err != nil { return resources, err @@ -47,6 +85,28 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { } } + tableDetails, err := dynamodbClient.DescribeTable(ctx, &dynamodb.DescribeTableInput{ + TableName: aws.String(table), + }) + + if err != nil { + return resources, err + } + + var provisionedRCUs *int64 + var provisionedWCUs *int64 + + if tableDetails != nil && tableDetails.Table != nil && tableDetails.Table.ProvisionedThroughput != nil { + provisionedRCUs = tableDetails.Table.ProvisionedThroughput.ReadCapacityUnits + provisionedWCUs = tableDetails.Table.ProvisionedThroughput.WriteCapacityUnits + } + + log.Errorf("ERROR: Failed to calculate cost per month: %v", err) + + RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], int64PtrToFloat64(provisionedRCUs)) + PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], int64PtrToFloat64(provisionedWCUs)) + monthlyCost := RCUCharges + PWUCharges + resources = append(resources, Resource{ Provider: "AWS", Account: client.Name, @@ -54,7 +114,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { ResourceId: resourceArn, Region: client.AWSClient.Region, Name: table, - Cost: 0, + Cost: monthlyCost, Tags: tags, FetchedAt: time.Now(), Link: fmt.Sprintf("https://%s.console.aws.amazon.com/dynamodbv2/home?region=%s#table?initialTagKey=&name=%s", client.AWSClient.Region, client.AWSClient.Region, table), From 9c70b10fbba3a327b589e853f13bbc24323f6d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:55:58 +0200 Subject: [PATCH 02/12] chore: cleanup and add util test --- providers/aws/dynamodb/tables.go | 8 +++++--- providers/aws/dynamodb/tables_test.go | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 providers/aws/dynamodb/tables_test.go diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 14e719fc0..a0dc89cf7 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/service/pricing/types" "github.com/aws/aws-sdk-go-v2/service/sts" awsUtils "github.com/tailwarden/komiser/providers/aws/utils" - // "github.com/tailwarden/komiser/utils" . "github.com/tailwarden/komiser/models" . "github.com/tailwarden/komiser/providers" ) @@ -90,6 +89,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { }) if err != nil { + log.Errorf("ERROR: Failed to query DynamoDB table details: %v", err) return resources, err } @@ -99,12 +99,14 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { if tableDetails != nil && tableDetails.Table != nil && tableDetails.Table.ProvisionedThroughput != nil { provisionedRCUs = tableDetails.Table.ProvisionedThroughput.ReadCapacityUnits provisionedWCUs = tableDetails.Table.ProvisionedThroughput.WriteCapacityUnits + } else { + log.Errorf("ERROR: Failed to calculate cost per month: %v", err) + return resources, err } - log.Errorf("ERROR: Failed to calculate cost per month: %v", err) - RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], int64PtrToFloat64(provisionedRCUs)) PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], int64PtrToFloat64(provisionedWCUs)) + monthlyCost := RCUCharges + PWUCharges resources = append(resources, Resource{ diff --git a/providers/aws/dynamodb/tables_test.go b/providers/aws/dynamodb/tables_test.go new file mode 100644 index 000000000..79faa5a0f --- /dev/null +++ b/providers/aws/dynamodb/tables_test.go @@ -0,0 +1,23 @@ +package dynamodb + +import ("testing") + +func Testint64PtrToFloat64_ValidInput(t *testing.T) { + var number int64 = 1 + pointer := &number + + returnValue := int64PtrToFloat64(pointer) + var expected float64 = 0.0 + if returnValue != expected { + t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) + } +} + +func Testint64PtrToFloat64_InvalidInput(t *testing.T) { + // nil input + returnValue := int64PtrToFloat64(nil) + var expected float64 = 3.0 + if returnValue != expected { + t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) + } +} From 4d876d60187fc2ee6f5e1de17300e7a8ec739c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Tue, 17 Oct 2023 18:44:18 +0200 Subject: [PATCH 03/12] fix: address linter errors --- providers/aws/dynamodb/tables.go | 7 ++++--- providers/aws/dynamodb/tables_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index a0dc89cf7..9340dcb17 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -17,7 +17,7 @@ import ( . "github.com/tailwarden/komiser/providers" ) -func int64PtrToFloat64(i *int64) float64 { +func Int64PtrToFloat64(i *int64) float64 { if i == nil { return 0.0 // or any default value you prefer } @@ -55,6 +55,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { output, err := dynamodbClient.ListTables(ctx, &config) + if err != nil { return resources, err } @@ -104,8 +105,8 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { return resources, err } - RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], int64PtrToFloat64(provisionedRCUs)) - PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], int64PtrToFloat64(provisionedWCUs)) + RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], Int64PtrToFloat64(provisionedRCUs)) + PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], Int64PtrToFloat64(provisionedWCUs)) monthlyCost := RCUCharges + PWUCharges diff --git a/providers/aws/dynamodb/tables_test.go b/providers/aws/dynamodb/tables_test.go index 79faa5a0f..d543f8271 100644 --- a/providers/aws/dynamodb/tables_test.go +++ b/providers/aws/dynamodb/tables_test.go @@ -2,20 +2,20 @@ package dynamodb import ("testing") -func Testint64PtrToFloat64_ValidInput(t *testing.T) { +func TestInt64PtrToFloat64_ValidInput(t *testing.T) { var number int64 = 1 pointer := &number - returnValue := int64PtrToFloat64(pointer) + returnValue := Int64PtrToFloat64(pointer) var expected float64 = 0.0 if returnValue != expected { t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) } } -func Testint64PtrToFloat64_InvalidInput(t *testing.T) { +func TestInt64PtrToFloat64_InvalidInput(t *testing.T) { // nil input - returnValue := int64PtrToFloat64(nil) + returnValue := Int64PtrToFloat64(nil) var expected float64 = 3.0 if returnValue != expected { t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) From 454aa9fa5675d280f00176d67e32141e0330331a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:31:12 +0200 Subject: [PATCH 04/12] fix: set correct expect values --- providers/aws/dynamodb/tables_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/providers/aws/dynamodb/tables_test.go b/providers/aws/dynamodb/tables_test.go index d543f8271..953545a76 100644 --- a/providers/aws/dynamodb/tables_test.go +++ b/providers/aws/dynamodb/tables_test.go @@ -7,16 +7,16 @@ func TestInt64PtrToFloat64_ValidInput(t *testing.T) { pointer := &number returnValue := Int64PtrToFloat64(pointer) - var expected float64 = 0.0 + var expected float64 = 1.0 if returnValue != expected { t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) } } -func TestInt64PtrToFloat64_InvalidInput(t *testing.T) { +func TestInt64PtrToFloat64_NilInput(t *testing.T) { // nil input returnValue := Int64PtrToFloat64(nil) - var expected float64 = 3.0 + var expected float64 = 0.0 if returnValue != expected { t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) } From cbe7a7950de5e3811da7cd03dc5d2e8fdd3468bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:36:19 +0200 Subject: [PATCH 05/12] fix: fix log --- providers/aws/dynamodb/tables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 9340dcb17..37c5a4ea5 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -43,7 +43,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { }) if err != nil { - log.Errorf("ERROR: Couldn't fetch pricing info for AWS Lambda: %v", err) + log.Errorf("ERROR: Couldn't fetch pricing info for AWS DynamoDB: %v", err) return resources, err } From 306596957b0cf20b1352339d22607c6c603fa4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:05:55 +0200 Subject: [PATCH 06/12] fix: set region to US before initializing pricing client --- providers/aws/dynamodb/tables.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 37c5a4ea5..702357a56 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -29,7 +29,10 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { resources := make([]Resource, 0) var config dynamodb.ListTablesInput dynamodbClient := dynamodb.NewFromConfig(*client.AWSClient) + oldRegion := client.AWSClient.Region + client.AWSClient.Region = "us-east-1" pricingClient := pricing.NewFromConfig(*client.AWSClient) + client.AWSClient.Region = oldRegion pricingOutput, err := pricingClient.GetProducts(ctx, &pricing.GetProductsInput{ ServiceCode: aws.String("AmazonDynamoDB"), From 400fc26e2126e43d63216da5c69aed185a4fa720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:54:07 +0200 Subject: [PATCH 07/12] fix: address review comment and move util into utils and also the tests. Rename log info --- providers/aws/dynamodb/tables.go | 9 +-------- providers/aws/dynamodb/tables_test.go | 23 ----------------------- providers/aws/utils/utils.go | 7 +++++++ providers/aws/utils/utils_test.go | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 31 deletions(-) delete mode 100644 providers/aws/dynamodb/tables_test.go diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 702357a56..3e8b53c1d 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -17,13 +17,6 @@ import ( . "github.com/tailwarden/komiser/providers" ) -func Int64PtrToFloat64(i *int64) float64 { - if i == nil { - return 0.0 // or any default value you prefer - } - return float64(*i) -} - func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { resources := make([]Resource, 0) @@ -52,7 +45,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { priceMap, err := awsUtils.GetPriceMap(pricingOutput, "group") if err != nil { - log.Errorf("ERROR: Failed to calculate cost per month: %v", err) + log.Errorf("ERROR: Failed to fetch pricing map: %v", err) return resources, err } diff --git a/providers/aws/dynamodb/tables_test.go b/providers/aws/dynamodb/tables_test.go deleted file mode 100644 index 953545a76..000000000 --- a/providers/aws/dynamodb/tables_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package dynamodb - -import ("testing") - -func TestInt64PtrToFloat64_ValidInput(t *testing.T) { - var number int64 = 1 - pointer := &number - - returnValue := Int64PtrToFloat64(pointer) - var expected float64 = 1.0 - if returnValue != expected { - t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) - } -} - -func TestInt64PtrToFloat64_NilInput(t *testing.T) { - // nil input - returnValue := Int64PtrToFloat64(nil) - var expected float64 = 0.0 - if returnValue != expected { - t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) - } -} diff --git a/providers/aws/utils/utils.go b/providers/aws/utils/utils.go index 529c00bcb..5ed566701 100644 --- a/providers/aws/utils/utils.go +++ b/providers/aws/utils/utils.go @@ -91,3 +91,10 @@ func GetPriceMap(pricingOutput *pricing.GetProductsOutput, field string) (map[st return priceMap, nil } + +func Int64PtrToFloat64(i *int64) float64 { + if i == nil { + return 0.0 // or any default value you prefer + } + return float64(*i) +} diff --git a/providers/aws/utils/utils_test.go b/providers/aws/utils/utils_test.go index bf2f6fb39..3b53d3268 100644 --- a/providers/aws/utils/utils_test.go +++ b/providers/aws/utils/utils_test.go @@ -234,3 +234,24 @@ func TestGetPriceMap_NoPricingOutput(t *testing.T) { t.Errorf("Expected an empty priceMap, but got %v", priceMap) } } + +func TestInt64PtrToFloat64_ValidInput(t *testing.T) { + var number int64 = 1 + pointer := &number + + returnValue := Int64PtrToFloat64(pointer) + var expected float64 = 1.0 + if returnValue != expected { + t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) + } +} + +func TestInt64PtrToFloat64_NilInput(t *testing.T) { + // nil input + returnValue := Int64PtrToFloat64(nil) + var expected float64 = 0.0 + if returnValue != expected { + t.Errorf("Expected return value: %f, but got: %f", expected, returnValue) + } +} + From dc5b786d1880e9d8728062b7488b62196a328e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:59:34 +0200 Subject: [PATCH 08/12] fix: add instance name to awscli util --- providers/aws/dynamodb/tables.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 3e8b53c1d..44b040c71 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -101,8 +101,8 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { return resources, err } - RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], Int64PtrToFloat64(provisionedRCUs)) - PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], Int64PtrToFloat64(provisionedWCUs)) + RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedRCUs)) + PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedWCUs)) monthlyCost := RCUCharges + PWUCharges From 53419b7aa3555e69edb5bb97c5f3c30bbd1f9a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:26:16 +0200 Subject: [PATCH 09/12] fix: address review comment and improve error handling --- providers/aws/dynamodb/tables.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 44b040c71..6b5fd13aa 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -22,6 +22,10 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { resources := make([]Resource, 0) var config dynamodb.ListTablesInput dynamodbClient := dynamodb.NewFromConfig(*client.AWSClient) + + var monthlyCost float64 = 0.0 + // there is something strange going on when using pricing client with reagions other than us-east-1 + // https://discord.com/channels/932683789384183808/1117721764957536318/1162338171435090032 oldRegion := client.AWSClient.Region client.AWSClient.Region = "us-east-1" pricingClient := pricing.NewFromConfig(*client.AWSClient) @@ -40,13 +44,12 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { if err != nil { log.Errorf("ERROR: Couldn't fetch pricing info for AWS DynamoDB: %v", err) - return resources, err } priceMap, err := awsUtils.GetPriceMap(pricingOutput, "group") + if err != nil { log.Errorf("ERROR: Failed to fetch pricing map: %v", err) - return resources, err } @@ -87,24 +90,17 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { if err != nil { log.Errorf("ERROR: Failed to query DynamoDB table details: %v", err) - return resources, err } - var provisionedRCUs *int64 - var provisionedWCUs *int64 - if tableDetails != nil && tableDetails.Table != nil && tableDetails.Table.ProvisionedThroughput != nil { - provisionedRCUs = tableDetails.Table.ProvisionedThroughput.ReadCapacityUnits - provisionedWCUs = tableDetails.Table.ProvisionedThroughput.WriteCapacityUnits - } else { - log.Errorf("ERROR: Failed to calculate cost per month: %v", err) - return resources, err - } + provisionedRCUs := tableDetails.Table.ProvisionedThroughput.ReadCapacityUnits + provisionedWCUs := tableDetails.Table.ProvisionedThroughput.WriteCapacityUnits - RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedRCUs)) - PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedWCUs)) + RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedRCUs)) + PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedWCUs)) - monthlyCost := RCUCharges + PWUCharges + monthlyCost = RCUCharges + PWUCharges + } resources = append(resources, Resource{ Provider: "AWS", From 8bb465506bc15beb7c4e7f1ad4da39df02deff56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:29:15 +0200 Subject: [PATCH 10/12] fix: fix typo --- providers/aws/dynamodb/tables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 6b5fd13aa..a0058bc2d 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -24,7 +24,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { dynamodbClient := dynamodb.NewFromConfig(*client.AWSClient) var monthlyCost float64 = 0.0 - // there is something strange going on when using pricing client with reagions other than us-east-1 + // there is something strange going on when using pricing client with regions other than us-east-1 // https://discord.com/channels/932683789384183808/1117721764957536318/1162338171435090032 oldRegion := client.AWSClient.Region client.AWSClient.Region = "us-east-1" From d0b4ca49cfe006494662df3cdccd770158c2f7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:06:12 +0200 Subject: [PATCH 11/12] fix: address review comment --- providers/aws/dynamodb/tables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index a0058bc2d..298056c56 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -92,7 +92,7 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { log.Errorf("ERROR: Failed to query DynamoDB table details: %v", err) } - if tableDetails != nil && tableDetails.Table != nil && tableDetails.Table.ProvisionedThroughput != nil { + if tableDetails.Table != nil && tableDetails.Table.ProvisionedThroughput != nil { provisionedRCUs := tableDetails.Table.ProvisionedThroughput.ReadCapacityUnits provisionedWCUs := tableDetails.Table.ProvisionedThroughput.WriteCapacityUnits From cdca2ad0a7a749637c35750fb549c1df976ea045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6sel?= <320272+Traxmaxx@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:21:39 +0200 Subject: [PATCH 12/12] fix: adress review comment and update pricing table unit --- providers/aws/dynamodb/tables.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/providers/aws/dynamodb/tables.go b/providers/aws/dynamodb/tables.go index 298056c56..b94a528b5 100644 --- a/providers/aws/dynamodb/tables.go +++ b/providers/aws/dynamodb/tables.go @@ -96,10 +96,10 @@ func Tables(ctx context.Context, client ProviderClient) ([]Resource, error) { provisionedRCUs := tableDetails.Table.ProvisionedThroughput.ReadCapacityUnits provisionedWCUs := tableDetails.Table.ProvisionedThroughput.WriteCapacityUnits - RCUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedReadCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedRCUs)) - PWUCharges := awsUtils.GetCost(priceMap["AWS-DynamoDB-ProvisionedWriteCapacityUnits"], awsUtils.Int64PtrToFloat64(provisionedWCUs)) + RCUCharges := awsUtils.GetCost(priceMap["DDB-ReadUnits"], awsUtils.Int64PtrToFloat64(provisionedRCUs)) + WCUCharges := awsUtils.GetCost(priceMap["DDB-WriteUnits"], awsUtils.Int64PtrToFloat64(provisionedWCUs)) - monthlyCost = RCUCharges + PWUCharges + monthlyCost = RCUCharges + WCUCharges } resources = append(resources, Resource{