Sha256: dadd774db3c89ab8cb07d4d619ca86b0aa529c852f92d7e52a0cd404587204de

Contents?: true

Size: 889 Bytes

Versions: 20

Compression:

Stored size: 889 Bytes

Contents

require 'yaml'
require 'terminal-table'

cmd = 'aws ce get-cost-and-usage        --time-period Start=2023-12-01,End=2023-12-31        --granularity MONTHLY        --metrics "UnblendedCost" "UsageQuantity"        --group-by Type=DIMENSION,Key=SERVICE'

# Parse the YAML content
text = system(cmd)
data = YAML.load(text)

# Extracting the relevant information
services = data["ResultsByTime"][0]["Groups"].map do |group|
  service_name = group["Keys"][0]
  unblended_cost = "#{group['Metrics']['UnblendedCost']['Amount']} #{group['Metrics']['UnblendedCost']['Unit']}"
  usage_quantity = "#{group['Metrics']['UsageQuantity']['Amount']} #{group['Metrics']['UsageQuantity']['Unit']}"
  [service_name, unblended_cost, usage_quantity]
end

# Create a table
table = Terminal::Table.new :headings => ['Service', 'Unblended Cost', 'Usage Quantity'], :rows => services

# Output the table
puts table

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
markdown_exec-2.3.0 lib/ce_get_cost_and_usage.rb
markdown_exec-2.2.0 lib/ce_get_cost_and_usage.rb
markdown_exec-2.1.0 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.8.4 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.8.3 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.8.2 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.8.1 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.8 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.7 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.6 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.5 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.4 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.3.2 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.3.1 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.3 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.2 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.1 lib/ce_get_cost_and_usage.rb
markdown_exec-2.0.0 lib/ce_get_cost_and_usage.rb
markdown_exec-1.8.9 lib/ce_get_cost_and_usage.rb
markdown_exec-1.8.8 lib/ce_get_cost_and_usage.rb