You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.
Class: Aws::CostExplorer::Client
- Inherits:
-
Seahorse::Client::Base
- Object
- Seahorse::Client::Base
- Aws::CostExplorer::Client
- Defined in:
- (unknown)
Overview
An API client for AWS Cost Explorer Service. To construct a client, you need to configure a :region
and :credentials
.
costexplorer = Aws::CostExplorer::Client.new(
region: region_name,
credentials: credentials,
# ...
)
See #initialize for a full list of supported configuration options.
Region
You can configure a default region in the following locations:
ENV['AWS_REGION']
Aws.config[:region]
Go here for a list of supported regions.
Credentials
Default credentials are loaded automatically from the following locations:
ENV['AWS_ACCESS_KEY_ID']
andENV['AWS_SECRET_ACCESS_KEY']
Aws.config[:credentials]
- The shared credentials ini file at
~/.aws/credentials
(more information) - From an instance profile when running on EC2
You can also construct a credentials object from one of the following classes:
Alternatively, you configure credentials with :access_key_id
and
:secret_access_key
:
# load credentials from disk
creds = YAML.load(File.read('/path/to/secrets'))
Aws::CostExplorer::Client.new(
access_key_id: creds['access_key_id'],
secret_access_key: creds['secret_access_key']
)
Always load your credentials from outside your application. Avoid configuring credentials statically and never commit them to source control.
Instance Attribute Summary
Attributes inherited from Seahorse::Client::Base
Constructor collapse
-
#initialize(options = {}) ⇒ Aws::CostExplorer::Client
constructor
Constructs an API client.
API Operations collapse
-
#create_anomaly_monitor(options = {}) ⇒ Types::CreateAnomalyMonitorResponse
Creates a new cost anomaly detection monitor with the requested type and monitor specification.
-
#create_anomaly_subscription(options = {}) ⇒ Types::CreateAnomalySubscriptionResponse
Adds a subscription to a cost anomaly detection monitor.
-
#create_cost_category_definition(options = {}) ⇒ Types::CreateCostCategoryDefinitionResponse
Creates a new Cost Category with the requested name and rules.
.
-
#delete_anomaly_monitor(options = {}) ⇒ Struct
Deletes a cost anomaly monitor.
-
#delete_anomaly_subscription(options = {}) ⇒ Struct
Deletes a cost anomaly subscription.
-
#delete_cost_category_definition(options = {}) ⇒ Types::DeleteCostCategoryDefinitionResponse
Deletes a Cost Category.
-
#describe_cost_category_definition(options = {}) ⇒ Types::DescribeCostCategoryDefinitionResponse
Returns the name, ARN, rules, definition, and effective dates of a Cost Category that's defined in the account.
You have the option to use
EffectiveOn
to return a Cost Category that is active on a specific date. -
#get_anomalies(options = {}) ⇒ Types::GetAnomaliesResponse
Retrieves all of the cost anomalies detected on your account, during the time period specified by the
DateInterval
object. -
#get_anomaly_monitors(options = {}) ⇒ Types::GetAnomalyMonitorsResponse
Retrieves the cost anomaly monitor definitions for your account.
-
#get_anomaly_subscriptions(options = {}) ⇒ Types::GetAnomalySubscriptionsResponse
Retrieves the cost anomaly subscription objects for your account.
-
#get_cost_and_usage(options = {}) ⇒ Types::GetCostAndUsageResponse
Retrieves cost and usage metrics for your account.
-
#get_cost_and_usage_with_resources(options = {}) ⇒ Types::GetCostAndUsageWithResourcesResponse
Retrieves cost and usage metrics with resources for your account.
-
#get_cost_forecast(options = {}) ⇒ Types::GetCostForecastResponse
Retrieves a forecast for how much Amazon Web Services predicts that you will spend over the forecast time period that you select, based on your past costs.
-
#get_dimension_values(options = {}) ⇒ Types::GetDimensionValuesResponse
Retrieves all available filter values for a specified filter over a period of time.
-
#get_reservation_coverage(options = {}) ⇒ Types::GetReservationCoverageResponse
Retrieves the reservation coverage for your account.
-
#get_reservation_purchase_recommendation(options = {}) ⇒ Types::GetReservationPurchaseRecommendationResponse
Gets recommendations for which reservations to purchase.
-
#get_reservation_utilization(options = {}) ⇒ Types::GetReservationUtilizationResponse
Retrieves the reservation utilization for your account.
-
#get_rightsizing_recommendation(options = {}) ⇒ Types::GetRightsizingRecommendationResponse
Creates recommendations that help you save cost by identifying idle and underutilized Amazon EC2 instances.
Recommendations are generated to either downsize or terminate instances, along with providing savings detail and metrics.
-
#get_savings_plans_coverage(options = {}) ⇒ Types::GetSavingsPlansCoverageResponse
Retrieves the Savings Plans covered for your account.
-
#get_savings_plans_purchase_recommendation(options = {}) ⇒ Types::GetSavingsPlansPurchaseRecommendationResponse
Retrieves your request parameters, Savings Plan Recommendations Summary and Details.
-
#get_savings_plans_utilization(options = {}) ⇒ Types::GetSavingsPlansUtilizationResponse
Retrieves the Savings Plans utilization for your account across date ranges with daily or monthly granularity.
-
#get_savings_plans_utilization_details(options = {}) ⇒ Types::GetSavingsPlansUtilizationDetailsResponse
Retrieves attribute data along with aggregate utilization and savings data for a given time period.
-
#get_tags(options = {}) ⇒ Types::GetTagsResponse
Queries for available tag keys and tag values for a specified period.
-
#get_usage_forecast(options = {}) ⇒ Types::GetUsageForecastResponse
Retrieves a forecast for how much Amazon Web Services predicts that you will use over the forecast time period that you select, based on your past usage.
-
#list_cost_category_definitions(options = {}) ⇒ Types::ListCostCategoryDefinitionsResponse
Returns the name, ARN,
NumberOfRules
and effective dates of all Cost Categories defined in the account. -
#provide_anomaly_feedback(options = {}) ⇒ Types::ProvideAnomalyFeedbackResponse
Modifies the feedback property of a given cost anomaly.
-
#update_anomaly_monitor(options = {}) ⇒ Types::UpdateAnomalyMonitorResponse
Updates an existing cost anomaly monitor.
-
#update_anomaly_subscription(options = {}) ⇒ Types::UpdateAnomalySubscriptionResponse
Updates an existing cost anomaly monitor subscription.
-
#update_cost_category_definition(options = {}) ⇒ Types::UpdateCostCategoryDefinitionResponse
Updates an existing Cost Category.
Instance Method Summary collapse
-
#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean
Waiters polls an API operation until a resource enters a desired state.
-
#waiter_names ⇒ Array<Symbol>
Returns the list of supported waiters.
Methods inherited from Seahorse::Client::Base
add_plugin, api, #build_request, clear_plugins, define, new, #operation, #operation_names, plugins, remove_plugin, set_api, set_plugins
Methods included from Seahorse::Client::HandlerBuilder
#handle, #handle_request, #handle_response
Constructor Details
#initialize(options = {}) ⇒ Aws::CostExplorer::Client
Constructs an API client.
Instance Method Details
#create_anomaly_monitor(options = {}) ⇒ Types::CreateAnomalyMonitorResponse
Creates a new cost anomaly detection monitor with the requested type and monitor specification.
#create_anomaly_subscription(options = {}) ⇒ Types::CreateAnomalySubscriptionResponse
Adds a subscription to a cost anomaly detection monitor. You can use each subscription to define subscribers with email or SNS notifications. Email subscribers can set a dollar threshold and a time frequency for receiving notifications.
#create_cost_category_definition(options = {}) ⇒ Types::CreateCostCategoryDefinitionResponse
Creates a new Cost Category with the requested name and rules.
#delete_anomaly_monitor(options = {}) ⇒ Struct
Deletes a cost anomaly monitor.
#delete_anomaly_subscription(options = {}) ⇒ Struct
Deletes a cost anomaly subscription.
#delete_cost_category_definition(options = {}) ⇒ Types::DeleteCostCategoryDefinitionResponse
Deletes a Cost Category. Expenses from this month going forward will no longer be categorized with this Cost Category.
#describe_cost_category_definition(options = {}) ⇒ Types::DescribeCostCategoryDefinitionResponse
Returns the name, ARN, rules, definition, and effective dates of a Cost Category that's defined in the account.
You have the option to use EffectiveOn
to return a Cost Category that is active on a specific date. If there is no EffectiveOn
specified, you’ll see a Cost Category that is effective on the current date. If Cost Category is still effective, EffectiveEnd
is omitted in the response.
#get_anomalies(options = {}) ⇒ Types::GetAnomaliesResponse
Retrieves all of the cost anomalies detected on your account, during the time period specified by the DateInterval
object.
#get_anomaly_monitors(options = {}) ⇒ Types::GetAnomalyMonitorsResponse
Retrieves the cost anomaly monitor definitions for your account. You can filter using a list of cost anomaly monitor Amazon Resource Names (ARNs).
#get_anomaly_subscriptions(options = {}) ⇒ Types::GetAnomalySubscriptionsResponse
Retrieves the cost anomaly subscription objects for your account. You can filter using a list of cost anomaly monitor Amazon Resource Names (ARNs).
#get_cost_and_usage(options = {}) ⇒ Types::GetCostAndUsageResponse
Retrieves 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 SERVICE
or AZ
, in a specific time range. For a complete list of valid dimensions, see the GetDimensionValues operation. Management account in an organization in AWS Organizations have access to all member accounts.
For information about filter limitations, see Quotas and restrictions in the Billing and Cost Management User Guide.
#get_cost_and_usage_with_resources(options = {}) ⇒ Types::GetCostAndUsageWithResourcesResponse
Retrieves cost and usage metrics with resources 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 SERVICE
or AZ
, in a specific time range. For a complete list of valid dimensions, see the GetDimensionValues operation. Management account in an organization in AWS Organizations have access to all member accounts. This API is currently available for the Amazon Elastic Compute Cloud – Compute service only.
This is an opt-in only feature. You can enable this feature from the Cost Explorer Settings page. For information on how to access the Settings page, see Controlling Access for Cost Explorer in the AWS Billing and Cost Management User Guide.
#get_cost_forecast(options = {}) ⇒ Types::GetCostForecastResponse
Retrieves a forecast for how much Amazon Web Services predicts that you will spend over the forecast time period that you select, based on your past costs.
#get_dimension_values(options = {}) ⇒ Types::GetDimensionValuesResponse
Retrieves all available filter values for a specified filter over a period of time. You can search the dimension values for an arbitrary string.
#get_reservation_coverage(options = {}) ⇒ Types::GetReservationCoverageResponse
Retrieves the reservation coverage for your account. This enables you to see how much of your Amazon Elastic Compute Cloud, Amazon ElastiCache, Amazon Relational Database Service, or Amazon Redshift usage is covered by a reservation. An organization's management account can see the coverage of the associated member accounts. This supports dimensions, Cost Categories, and nested expressions. For any time period, you can filter data about reservation usage by the following dimensions:
-
AZ
-
CACHE_ENGINE
-
DATABASE_ENGINE
-
DEPLOYMENT_OPTION
-
INSTANCE_TYPE
-
LINKED_ACCOUNT
-
OPERATING_SYSTEM
-
PLATFORM
-
REGION
-
SERVICE
-
TAG
-
TENANCY
To determine valid values for a dimension, use the GetDimensionValues
operation.
#get_reservation_purchase_recommendation(options = {}) ⇒ Types::GetReservationPurchaseRecommendationResponse
Gets recommendations for which reservations to purchase. These recommendations could help you reduce your costs. Reservations provide a discounted hourly rate (up to 75%) compared to On-Demand pricing.
AWS generates your recommendations by identifying your On-Demand usage during a specific time period and collecting your usage into categories that are eligible for a reservation. After AWS has these categories, it simulates every combination of reservations in each category of usage to identify the best number of each type of RI to purchase to maximize your estimated savings.
For example, AWS automatically aggregates your Amazon EC2 Linux, shared tenancy, and c4 family usage in the US West (Oregon) Region and recommends that you buy size-flexible regional reservations to apply to the c4 family usage. AWS recommends the smallest size instance in an instance family. This makes it easier to purchase a size-flexible RI. AWS also shows the equal number of normalized units so that you can purchase any instance size that you want. For this example, your RI recommendation would be for c4.large
because that is the smallest size instance in the c4 instance family.
#get_reservation_utilization(options = {}) ⇒ Types::GetReservationUtilizationResponse
Retrieves the reservation utilization for your account. Management account in an organization have access to 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
.
#get_rightsizing_recommendation(options = {}) ⇒ Types::GetRightsizingRecommendationResponse
Creates recommendations that help you save cost by identifying idle and underutilized Amazon EC2 instances.
Recommendations are generated to either downsize or terminate instances, along with providing savings detail and metrics. For details on calculation and function, see Optimizing Your Cost with Rightsizing Recommendations in the AWS Billing and Cost Management User Guide.
#get_savings_plans_coverage(options = {}) ⇒ Types::GetSavingsPlansCoverageResponse
Retrieves the Savings Plans covered for your account. This enables you to see how much of your cost is covered by a Savings Plan. An organization’s management account can see the coverage of the associated member accounts. This supports dimensions, Cost Categories, and nested expressions. For any time period, you can filter data for Savings Plans usage with the following dimensions:
-
LINKED_ACCOUNT
-
REGION
-
SERVICE
-
INSTANCE_FAMILY
To determine valid values for a dimension, use the GetDimensionValues
operation.
#get_savings_plans_purchase_recommendation(options = {}) ⇒ Types::GetSavingsPlansPurchaseRecommendationResponse
Retrieves your request parameters, Savings Plan Recommendations Summary and Details.
#get_savings_plans_utilization(options = {}) ⇒ Types::GetSavingsPlansUtilizationResponse
Retrieves the Savings Plans utilization for your account across date ranges with daily or monthly granularity. Management account in an organization have access to member accounts. You can use GetDimensionValues
in SAVINGS_PLANS
to determine the possible dimension values.
You cannot group by any dimension values for GetSavingsPlansUtilization
.
#get_savings_plans_utilization_details(options = {}) ⇒ Types::GetSavingsPlansUtilizationDetailsResponse
Retrieves attribute data along with aggregate utilization and savings data for a given time period. This doesn't support granular or grouped data (daily/monthly) in response. You can't retrieve data by dates in a single response similar to GetSavingsPlanUtilization
, but you have the option to make multiple calls to GetSavingsPlanUtilizationDetails
by providing individual dates. You can use GetDimensionValues
in SAVINGS_PLANS
to determine the possible dimension values.
GetSavingsPlanUtilizationDetails
internally groups data by SavingsPlansArn
.
#get_tags(options = {}) ⇒ Types::GetTagsResponse
Queries for available tag keys and tag values for a specified period. You can search the tag values for an arbitrary string.
#get_usage_forecast(options = {}) ⇒ Types::GetUsageForecastResponse
Retrieves a forecast for how much Amazon Web Services predicts that you will use over the forecast time period that you select, based on your past usage.
#list_cost_category_definitions(options = {}) ⇒ Types::ListCostCategoryDefinitionsResponse
Returns the name, ARN, NumberOfRules
and effective dates of all Cost Categories defined in the account. You have the option to use EffectiveOn
to return a list of Cost Categories that were active on a specific date. If there is no EffectiveOn
specified, you’ll see Cost Categories that are effective on the current date. If Cost Category is still effective, EffectiveEnd
is omitted in the response. ListCostCategoryDefinitions
supports pagination. The request can have a MaxResults
range up to 100.
#provide_anomaly_feedback(options = {}) ⇒ Types::ProvideAnomalyFeedbackResponse
Modifies the feedback property of a given cost anomaly.
#update_anomaly_monitor(options = {}) ⇒ Types::UpdateAnomalyMonitorResponse
Updates an existing cost anomaly monitor. The changes made are applied going forward, and does not change anomalies detected in the past.
#update_anomaly_subscription(options = {}) ⇒ Types::UpdateAnomalySubscriptionResponse
Updates an existing cost anomaly monitor subscription.
#update_cost_category_definition(options = {}) ⇒ Types::UpdateCostCategoryDefinitionResponse
Updates an existing Cost Category. Changes made to the Cost Category rules will be used to categorize the current month’s expenses and future expenses. This won’t change categorization for the previous months.
#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean
Waiters polls an API operation until a resource enters a desired state.
Basic Usage
Waiters will poll until they are succesful, they fail by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop, sleeping between attempts client.waiter_until(waiter_name, params)
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. You configure waiters by passing a block to #wait_until:
# poll for ~25 seconds
client.wait_until(...) do |w|
w.max_attempts = 5
w.delay = 5
end
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success
or :failure
from these callbacks,
it will terminate the waiter.
started_at = Time.now
client.wait_until(...) do |w|
# disable max attempts
w.max_attempts = nil
# poll for 1 hour, instead of a number of attempts
w.before_wait do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
end
Handling Errors
When a waiter is successful, it returns true
. When a waiter
fails, it raises an error. All errors raised extend from
Waiters::Errors::WaiterFailed.
begin
client.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
#waiter_names ⇒ Array<Symbol>
Returns the list of supported waiters. The following table lists the supported waiters and the client method they call:
Waiter Name | Client Method | Default Delay: | Default Max Attempts: |
---|