#!/usr/bin/env node
const { spawn } = require('child_process');
async function getCloudWatchAmortized30Days() {
console.log('π° CLOUDWATCH 30-DAY AMORTIZED COST');
console.log('=' .repeat(40));
console.log('π
Period: July 27 - August 26, 2025 (30 days)');
console.log('π³ Cost Type: Amortized');
console.log('π§ Service: Amazon CloudWatch');
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
UMBRELLA_API_BASE_URL: 'https://api-front.umbrellacost.io/api/v1'
}
});
const responses = [];
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const response = JSON.parse(line);
responses.push(response);
} catch (e) {}
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
// Auth
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 1, method: "tools/call",
params: {
name: 'authenticate_user',
arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }
}
}) + '\n');
console.log('π Authenticating...');
await new Promise(resolve => setTimeout(resolve, 5000));
// Get account info first
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 2, method: "tools/call",
params: { name: 'api__user_management_accounts', arguments: {} }
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 3000));
const accountsResponse = responses.find(r => r.id === 2);
let accountId = null;
if (accountsResponse?.result?.content?.[0]?.text) {
const text = accountsResponse.result.content[0].text;
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
if (data.accounts && data.accounts.length > 0) {
accountId = data.accounts[0].linkedaccid;
console.log(`π’ Using account: ${accountId}`);
}
} catch (e) {}
}
}
if (!accountId) {
console.log('β Could not get account ID');
server.kill();
return;
}
// CloudWatch amortized cost query
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 3, method: "tools/call",
params: {
name: 'api__invoices_caui',
arguments: {
startDate: "2025-07-27",
endDate: "2025-08-26",
groupBy: "service",
periodGranLevel: "day",
costType: ["cost"],
isAmortized: "true",
cloud_context: "aws",
accountId: accountId,
filters: {
service: "Amazon CloudWatch"
}
}
}
}) + '\n');
console.log('π Getting CloudWatch amortized costs...');
let found = false;
for (let i = 0; i < 25 && !found; i++) {
await new Promise(resolve => setTimeout(resolve, 1000));
const response = responses.find(r => r.id === 3);
if (response?.result?.content?.[0]?.text) {
found = true;
const text = response.result.content[0].text;
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
console.log('\nπ° CLOUDWATCH AMORTIZED COSTS (30 DAYS)');
console.log('=' .repeat(45));
if (data.results && data.results.length > 0) {
let totalCost = 0;
data.results.forEach((day, i) => {
const date = day.date;
const cost = parseFloat(day.cost || 0);
totalCost += cost;
if (cost > 0) {
console.log(`π
${date}: $${cost.toFixed(4)}`);
}
});
console.log(`\nπ TOTAL CLOUDWATCH AMORTIZED COST: $${totalCost.toFixed(4)}`);
console.log(`π Service: Amazon CloudWatch`);
console.log(`π
Period: 30 days (July 27 - August 26, 2025)`);
console.log(`π³ Cost Type: Amortized`);
console.log(`π Daily Average: $${(totalCost / 30).toFixed(4)}`);
if (totalCost > 0) {
console.log('\nβ
CloudWatch amortized cost calculation successful');
} else {
console.log('\nβ οΈ Zero cost detected - may indicate no CloudWatch usage in this period');
}
} else {
console.log('β No cost data found');
console.log('Response keys:', Object.keys(data));
}
} catch (e) {
console.log('β JSON parsing error:', e.message);
}
} else {
console.log('β No JSON found in response');
console.log('Response preview:', text.substring(0, 200));
}
break;
}
if (i % 10 === 0 && i > 0) console.log(`β³ ${i}s...`);
}
if (!found) {
console.log('β No response within 25 seconds');
}
server.kill();
}
getCloudWatchAmortized30Days().catch(console.error);