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