aws / aws-sdk-go

AWS SDK for the Go programming language.

Home Page:http://aws.amazon.com/sdk-for-go/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cost Explorer Api. Can't group request by Tag.

girolamodaschio opened this issue · comments

Describe the bug

The current version of the AWS SDK for Go lacks the capability to group AWS Cost Explorer responses by tag.
This feature is crucial for users who need to analyse and manage costs efficiently based on specific tags associated with their AWS resources.

Expected Behavior

The SDK should provide a method or functionality that allows users to group Cost Explorer responses by tag, enabling them to gain insights into costs associated with specific resource categories.
Instead, it returns a TAGS$ as the key.

Current Behavior

The snippet code as written below returns
this structure of data:



  Estimated: false,
  Groups: [{
      Keys: ["TAGS$"],
      Metrics: {
        BlendedCost: {
          Amount: "21.4009595589",
          Unit: "USD"
        }
      }
    }],
  TimePeriod: {
    End: "2023-11-16",
    Start: "2023-11-15"
  },
  Total: {

  }
}

Reproduction Steps

func getCostByTag(session *session.Session) (*costexplorer.GetCostAndUsageOutput, error) {
	svc := costexplorer.New(session)

	resp, err := svc.GetCostAndUsage(&costexplorer.GetCostAndUsageInput{
		Metrics:     []*string{aws.String("BlendedCost")},
		TimePeriod:  getDates(),
		Granularity: aws.String("DAILY"),
		GroupBy: []*costexplorer.GroupDefinition{
			&costexplorer.GroupDefinition{
				Key:  aws.String("TAGS"),
				Type: aws.String("TAG"),
			},
		},
	})

	if err != nil {
		fmt.Println("Error getting cost data:", err)
		return nil, err
	}

	return resp, nil
}

Possible Solution

I'm trying to accomplish what's written here:
// When you group by the TAG type and include a valid tag key, you get all tag
// values, including empty strings.
GroupBy []*GroupDefinition type:"list"

https://github.com/aws/aws-sdk-go/blob/v1.49.2/service/costexplorer/api.go#L7782-L7847

Additional Information/Context

No response

SDK version used

github.com/aws/aws-sdk-go v1.49.2

Environment details (Version of Go (go version)? OS name and version, etc.)

go version go1.21.4 darwin/arm64

Was a futile mistake on the groupby.
Adding the correct tag fixed it.

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.