Sha256: cccd3797016f4f55ca894e93c9b088301c05b2a833ccb87098c892a178801123

Contents?: true

Size: 911 Bytes

Versions: 2

Compression:

Stored size: 911 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

2 entries across 2 versions & 1 rubygems

Version Path
markdown_exec-2.5.0 lib/ce_get_cost_and_usage.rb
markdown_exec-2.4.0 lib/ce_get_cost_and_usage.rb