You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::CostExplorer::Client

Inherits:
Seahorse::Client::Base show all
Includes:
Aws::ClientStubs
Defined in:
gems/aws-sdk-costexplorer/lib/aws-sdk-costexplorer/client.rb

Instance Attribute Summary

Attributes inherited from Seahorse::Client::Base

#config, #handlers

API Operations collapse

Instance Method Summary collapse

Methods included from Aws::ClientStubs

#stub_data, #stub_responses

Methods inherited from Seahorse::Client::Base

add_plugin, api, clear_plugins, define, new, #operation_names, plugins, remove_plugin, set_api, set_plugins

Methods included from Seahorse::Client::HandlerBuilder

#handle, #handle_request, #handle_response

Constructor Details

#initialize(*args) ⇒ Client

Returns a new instance of Client

Parameters:

  • options (Hash)

    a customizable set of options



152
153
154
# File 'gems/aws-sdk-costexplorer/lib/aws-sdk-costexplorer/client.rb', line 152

def initialize(*args)
  super
end

Instance Method Details

#get_cost_and_usage(params = {}) ⇒ Types::GetCostAndUsageResponse

Retrieve cost and usage metrics for your account. You can specify which cost and usage-related metric, such as BlendedCosts or UsageQuantity, that you want the request to return. You can also filter and group your data by various dimensions, such as AWS Service or AvailabilityZone, in a specific time range. See the GetDimensionValues action for a complete list of the valid dimensions. Master accounts in an organization have access to all member accounts.

Examples:

Request syntax with placeholder values


resp = client.get_cost_and_usage({
  time_period: {
    start: "YearMonthDay", # required
    end: "YearMonthDay", # required
  },
  granularity: "DAILY", # accepts DAILY, MONTHLY
  filter: {
    or: [
      {
        # recursive Expression
      },
    ],
    and: [
      {
        # recursive Expression
      },
    ],
    not: {
      # recursive Expression
    },
    dimensions: {
      key: "AZ", # accepts AZ, INSTANCE_TYPE, LINKED_ACCOUNT, OPERATION, PURCHASE_TYPE, REGION, SERVICE, USAGE_TYPE, USAGE_TYPE_GROUP, RECORD_TYPE, OPERATING_SYSTEM, TENANCY, SCOPE, PLATFORM, SUBSCRIPTION_ID
      values: ["Value"],
    },
    tags: {
      key: "TagKey",
      values: ["Value"],
    },
  },
  metrics: ["MetricName"],
  group_by: [
    {
      type: "DIMENSION", # accepts DIMENSION, TAG
      key: "GroupDefinitionKey",
    },
  ],
  next_page_token: "NextPageToken",
})

Response structure


resp.next_page_token #=> String
resp.group_definitions #=> Array
resp.group_definitions[0].type #=> String, one of "DIMENSION", "TAG"
resp.group_definitions[0].key #=> String
resp.results_by_time #=> Array
resp.results_by_time[0].time_period.start #=> String
resp.results_by_time[0].time_period.end #=> String
resp.results_by_time[0].total #=> Hash
resp.results_by_time[0].total["MetricName"].amount #=> String
resp.results_by_time[0].total["MetricName"].unit #=> String
resp.results_by_time[0].groups #=> Array
resp.results_by_time[0].groups[0].keys #=> Array
resp.results_by_time[0].groups[0].keys[0] #=> String
resp.results_by_time[0].groups[0].metrics #=> Hash
resp.results_by_time[0].groups[0].metrics["MetricName"].amount #=> String
resp.results_by_time[0].groups[0].metrics["MetricName"].unit #=> String
resp.results_by_time[0].estimated #=> Boolean

Parameters:

  • params (Hash) (defaults to: {})

    ({})

Options Hash (params):

  • :time_period (Types::DateInterval)

    Sets the start and end dates for retrieving AWS costs. The start date is inclusive, but the end date is exclusive. For example, if start is 2017-01-01 and end is 2017-05-01, then the cost and usage data is retrieved from 2017-01-01 up to and including 2017-04-30 but not including 2017-05-01.

  • :granularity (String)

    Sets the AWS cost granularity to MONTHLY or DAILY.

  • :filter (Types::Expression)

    Filters AWS costs by different dimensions. For example, you can specify Service and Linked Account and get the costs associated with that account's usage of that service. You can nest Expression objects to define any combination of dimension filters. For more information, see the Expression object or More Examples.

  • :metrics (Array<String>)

    Which metrics are returned in the query. For more information about blended and unblended rates, see https://aws.amazon.com/premiumsupport/knowledge-center/blended-rates-intro/.

    Valid values are BlendedCost, UnblendedCost, and UsageQuantity.

    If you return the UsageQuantity metric, the service aggregates all usage numbers without taking into account the units. For example, if you aggregate usageQuantity across all of EC2, the results aren't meaningful because EC2 compute hours and data transfer are measured in different units (for example, hours vs. GB). To get more meaningful UsageQuantity metrics, filter by UsageType or UsageTypeGroups.

  • :group_by (Array<Types::GroupDefinition>)

    You can group AWS costs using up to two different groups, either dimensions, tag keys, or both.

    When you group by tag key, you get all tag values, including empty strings.

    Valid values are: AZ, INSTANCE_TYPE, LINKED_ACCCOUNT, OPERATION, PURCHASE_TYPE, SERVICE, USAGE_TYPE, TAGS, and PLATFORM.

  • :next_page_token (String)

    The token to retrieve the next set of results. AWS provides the token when the response from a previous call has more results than the maximum page size.

Returns:

See Also:



287
288
289
290
# File 'gems/aws-sdk-costexplorer/lib/aws-sdk-costexplorer/client.rb', line 287

def get_cost_and_usage(params = {}, options = {})
  req = build_request(:get_cost_and_usage, params)
  req.send_request(options)
end

#get_dimension_values(params = {}) ⇒ Types::GetDimensionValuesResponse

You can use GetDimensionValues to retrieve all available filter values for a specific filter over a period of time. You can search the dimension values for an arbitrary string.

Examples:

Request syntax with placeholder values


resp = client.get_dimension_values({
  search_string: "SearchString",
  time_period: { # required
    start: "YearMonthDay", # required
    end: "YearMonthDay", # required
  },
  dimension: "AZ", # required, accepts AZ, INSTANCE_TYPE, LINKED_ACCOUNT, OPERATION, PURCHASE_TYPE, REGION, SERVICE, USAGE_TYPE, USAGE_TYPE_GROUP, RECORD_TYPE, OPERATING_SYSTEM, TENANCY, SCOPE, PLATFORM, SUBSCRIPTION_ID
  context: "COST_AND_USAGE", # accepts COST_AND_USAGE, RESERVATIONS
  next_page_token: "NextPageToken",
})

Response structure


resp.dimension_values #=> Array
resp.dimension_values[0].value #=> String
resp.dimension_values[0].attributes #=> Hash
resp.dimension_values[0].attributes["AttributeType"] #=> <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
resp.return_size #=> Integer
resp.total_size #=> Integer
resp.next_page_token #=> String

Parameters:

  • params (Hash) (defaults to: {})

    ({})

Options Hash (params):

  • :search_string (String)

    The value that you want to search the filter values for.

  • :time_period (required, Types::DateInterval)

    The start and end dates for retrieving the dimension values. The start date is inclusive, but the end date is exclusive. For example, if start is 2017-01-01 and end is 2017-05-01, then the cost and usage data is retrieved from 2017-01-01 up to and including 2017-04-30 but not including 2017-05-01.

  • :dimension (required, String)

    The name of the dimension. Different Dimensionsare available for different Contexts. For more information, see Context.

  • :context (String)

    The context for the call to GetDimensionValues. This can be RESERVED_INSTANCE or COST_AND_USAGE. The default value is COST_AND_USAGE. If the context is set to RESERVED_INSTANCE, the resulting dimension values can be used in the GetReservationUtilization action. If the context is set to COST_AND_USAGE, , the resulting dimension values can be used in the GetCostAndUsage operation.

    If you set the context to CostAndUsage, you can use the following dimensions for searching:

    • AZ - The Availability Zone. An example is us-east-1a.

    • InstanceType - The type of EC2 instance. An example is m4.xlarge.

    • LinkedAccount - The description in the attribute map that includes the full name of the member account. The value field contains the AWS ID of the member account

    • Operation - The action performed. Examples include RunInstance and CreateBucket.

    • PurchaseType - The reservation type of the purchase to which this usage is related. Examples include: On Demand Instances and Standard Reserved Instances

    • Service - The AWS service such as DynamoDB.

    • UsageType -The type of usage. An example is DataTransfer-In-Bytes. The response for the GetDimensionValues action includes a unit attribute, examples of which include GB and Hrs.

    • UsageTypeGroup - The grouping of common usage types. An example is EC2: CloudWatch – Alarms. The response for this action includes a unit attribute.

    • RecordType - The different types of charges such as RI fees, usage costs, tax refunds, and credits

    If you set the context to ReservedInstance, you can use the following dimensions for searching:

    • AZ - The Availability Zone. An example is us-east-1a.

    • InstanceType - The type of EC2 instance. An example is m4.xlarge.

    • LinkedAccount - The description in the attribute map that includes the full name of the member account. The value field contains the AWS ID of the member account

    • Platform - The operating system. Examples are Windows or Linux.

    • Region - The AWS region.

    • Scope - The scope of a reserved instance (RI). Values are regional or a single availability zone.

    • Tenancy - The tenancy of a resource. Examples are shared or dedicated.

  • :next_page_token (String)

    The token to retrieve the next set of results. AWS provides the token when the response from a previous call has more results than the maximum page size.

Returns:

See Also:



410
411
412
413
# File 'gems/aws-sdk-costexplorer/lib/aws-sdk-costexplorer/client.rb', line 410

def get_dimension_values(params = {}, options = {})
  req = build_request(:get_dimension_values, params)
  req.send_request(options)
end

#get_reservation_utilization(params = {}) ⇒ Types::GetReservationUtilizationResponse

You can retrieve the Reservation utilization for your account. Master accounts in an organization have access to their associated member accounts. You can filter data by dimensions in a time period. You can use GetDimensionValues to determine the possible dimension values. Currently, you can group only by SUBSCRIPTION_ID.

Examples:

Request syntax with placeholder values


resp = client.get_reservation_utilization({
  time_period: { # required
    start: "YearMonthDay", # required
    end: "YearMonthDay", # required
  },
  group_by: [
    {
      type: "DIMENSION", # accepts DIMENSION, TAG
      key: "GroupDefinitionKey",
    },
  ],
  granularity: "DAILY", # accepts DAILY, MONTHLY
  filter: {
    or: [
      {
        # recursive Expression
      },
    ],
    and: [
      {
        # recursive Expression
      },
    ],
    not: {
      # recursive Expression
    },
    dimensions: {
      key: "AZ", # accepts AZ, INSTANCE_TYPE, LINKED_ACCOUNT, OPERATION, PURCHASE_TYPE, REGION, SERVICE, USAGE_TYPE, USAGE_TYPE_GROUP, RECORD_TYPE, OPERATING_SYSTEM, TENANCY, SCOPE, PLATFORM, SUBSCRIPTION_ID
      values: ["Value"],
    },
    tags: {
      key: "TagKey",
      values: ["Value"],
    },
  },
  next_page_token: "NextPageToken",
})

Response structure


resp.utilizations_by_time #=> Array
resp.utilizations_by_time[0].time_period.start #=> String
resp.utilizations_by_time[0].time_period.end #=> String
resp.utilizations_by_time[0].groups #=> Array
resp.utilizations_by_time[0].groups[0].key #=> String
resp.utilizations_by_time[0].groups[0].value #=> String
resp.utilizations_by_time[0].groups[0].attributes #=> Hash
resp.utilizations_by_time[0].groups[0].attributes["AttributeType"] #=> <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
resp.utilizations_by_time[0].groups[0].utilization.utilization_percentage #=> String
resp.utilizations_by_time[0].groups[0].utilization.purchased_hours #=> String
resp.utilizations_by_time[0].groups[0].utilization.total_actual_hours #=> String
resp.utilizations_by_time[0].groups[0].utilization.unused_hours #=> String
resp.utilizations_by_time[0].total.utilization_percentage #=> String
resp.utilizations_by_time[0].total.purchased_hours #=> String
resp.utilizations_by_time[0].total.total_actual_hours #=> String
resp.utilizations_by_time[0].total.unused_hours #=> String
resp.total.utilization_percentage #=> String
resp.total.purchased_hours #=> String
resp.total.total_actual_hours #=> String
resp.total.unused_hours #=> String
resp.next_page_token #=> String

Parameters:

  • params (Hash) (defaults to: {})

    ({})

Options Hash (params):

  • :time_period (required, Types::DateInterval)

    Sets the start and end dates for retrieving reserve instance (RI) utilization. The start date is inclusive, but the end date is exclusive. For example, if start is 2017-01-01 and end is 2017-05-01, then the cost and usage data is retrieved from 2017-01-01 up to and including 2017-04-30 but not including 2017-05-01.

  • :group_by (Array<Types::GroupDefinition>)

    Groups only by SubscriptionId. Metadata is included.

  • :granularity (String)

    Sets the AWS cost granularity to MONTHLY or DAILY. If both GroupBy and granularity are not set, GetReservationUtilization defaults to DAILY. If GroupBy is set, Granularity can't be set, and the response object doesn't include MONTHLY or DAILY granularity.

  • :filter (Types::Expression)

    Filters utilization data by using different dimensions. GetReservationUtilization uses the same Expression object as the other operations, but only AND is supported among each dimension, and nesting is supported up to only one level deep. If there are multiple values for a dimension, they are OR'd together.

  • :next_page_token (String)

    The token to retrieve the next set of results. AWS provides the token when the response from a previous call has more results than the maximum page size.

Returns:

See Also:



525
526
527
528
# File 'gems/aws-sdk-costexplorer/lib/aws-sdk-costexplorer/client.rb', line 525

def get_reservation_utilization(params = {}, options = {})
  req = build_request(:get_reservation_utilization, params)
  req.send_request(options)
end

#get_tags(params = {}) ⇒ Types::GetTagsResponse

You can query for available tag keys and tag values for a specified period. You can search the tag values for an arbitrary string.

Examples:

Request syntax with placeholder values


resp = client.get_tags({
  search_string: "SearchString",
  time_period: { # required
    start: "YearMonthDay", # required
    end: "YearMonthDay", # required
  },
  tag_key: "TagKey",
  next_page_token: "NextPageToken",
})

Response structure


resp.next_page_token #=> String
resp.tags #=> Array
resp.tags[0] #=> String
resp.return_size #=> Integer
resp.total_size #=> Integer

Parameters:

  • params (Hash) (defaults to: {})

    ({})

Options Hash (params):

  • :search_string (String)

    The value that you want to search for.

  • :time_period (required, Types::DateInterval)

    The start and end dates for retrieving the dimension values. The start date is inclusive, but the end date is exclusive. For example, if start is 2017-01-01 and end is 2017-05-01, then the cost and usage data is retrieved from 2017-01-01 up to and including 2017-04-30 but not including 2017-05-01.

  • :tag_key (String)

    The key of the tag that you want to return values for.

  • :next_page_token (String)

    The token to retrieve the next set of results. AWS provides the token when the response from a previous call has more results than the maximum page size.

Returns:

See Also:



582
583
584
585
# File 'gems/aws-sdk-costexplorer/lib/aws-sdk-costexplorer/client.rb', line 582

def get_tags(params = {}, options = {})
  req = build_request(:get_tags, params)
  req.send_request(options)
end