#!/usr/bin/env node
const { spawn } = require('child_process');
async function getFinalCloudWatchCost() {
console.log('💰 CLOUDWATCH 30-DAY AMORTIZED COST - FINAL ATTEMPT');
console.log('🏢 AWS Account: 932213950603');
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 {
responses.push(JSON.parse(line));
} catch (e) {}
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
// Auth with longer wait
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, 6000)); // Longer wait
// CloudWatch 30-day amortized cost
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 2, 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: "932213950603",
service: "Amazon CloudWatch"
}
}
}) + '\n');
console.log('🔍 Requesting CloudWatch costs (30 days, amortized)...');
// Wait longer for cost data
for (let i = 0; i < 45; i++) {
await new Promise(resolve => setTimeout(resolve, 1000));
const response = responses.find(r => r.id === 2);
if (response?.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
console.log('✅ Response received!');
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
if (data.results && data.results.length > 0) {
let totalCost = 0;
console.log('\n💰 CloudWatch Daily Amortized Costs:');
data.results.forEach(day => {
const cost = parseFloat(day.cost || 0);
if (cost > 0) {
totalCost += cost;
console.log(`📅 ${day.date}: $${cost.toFixed(8)}`);
}
});
console.log(`\n🏆 ANSWER: CloudWatch 30-day amortized cost = $${totalCost.toFixed(8)}`);
console.log(`🏢 Account: 932213950603`);
console.log(`📅 Period: July 27 - August 26, 2025`);
break;
} else {
console.log('❌ No cost results found');
if (data.error) console.log('Error:', data.error);
}
} catch (e) {
console.log('❌ Parse error:', e.message);
}
} else {
if (text.includes('No authenticated users')) {
console.log('❌ Authentication failed');
} else {
console.log('Response:', text.substring(0, 200));
}
}
break;
}
if (i % 10 === 0 && i > 0) console.log(`⏳ ${i}s...`);
}
server.kill();
}
getFinalCloudWatchCost().catch(console.error);