我发现此参考https://docs.aws.amazon.com/sdkforruby/api/Aws/CostExplorer/Client.html#initialize-instance_method 用于查找 ec2 实例使用的成本,而在实施阶段我遇到了异常。
在 gem 文件中我使用了这个 gem 'aws-sdk', '~> 3'
cost_client = Aws::CostExplorer::Client.new(
region: "us-east-1",
access_key_id: "XXXX",
secret_access_key: "XXX"
)
resp = cost_client.get_cost_and_usage({
time_period: { # required
start: "2019-01-01", # required
end: "2019-05-01", # required
},
granularity: "DAILY", # accepts DAILY, MONTHLY, HOURLY
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, LEGAL_ENTITY_NAME, DEPLOYMENT_OPTION, DATABASE_ENGINE, CACHE_ENGINE, INSTANCE_TYPE_FAMILY, BILLING_ENTITY, RESERVATION_ID
values: ["Value"],
},
tags: {
key: "TagKey",
values: ["Value"],
},
},
metrics: ["MetricName"],
group_by: [
{
type: "DIMENSION", # accepts DIMENSION, TAG
key: "GroupDefinitionKey",
},
],
next_page_token: "NextPageToken",
})
我得到了这个异常 NameError: uninitialized constant Aws::CostExplorer.我怎样才能从这个 api 得到响应?