import { AwsService } from './services/aws-service'; import { AwsConnectionResult } from './types/client'; import { logger } from './utils/logger'; /** * Display troubleshooting suggestions for AWS connection failures */ function displayTroubleshootingSuggestions(): void { logger.info('\nTroubleshooting suggestions:'); logger.info('1. Check that you have valid AWS credentials'); logger.info('2. Ensure your credentials have permission to access CloudWatch Logs'); logger.info('3. Verify your region is correct'); logger.info('4. Try setting AWS_PROFILE if you use credential profiles'); logger.info('5. Check your network connectivity to AWS'); } /** * Handle successful connection result * @param result Successful connection result */ function handleSuccessResult(result: AwsConnectionResult): void { logger.info(result.message); if (result.logGroupName) { logger.info(`Found log group: ${result.logGroupName}`); } } /** * Handle failed connection result * @param result Failed connection result */ function handleFailureResult(result: AwsConnectionResult): void { logger.error(result.message); if (result.error) { logger.error('Error details:', result.error); } // Provide helpful troubleshooting guidance displayTroubleshootingSuggestions(); } /** * Simple utility to test AWS CloudWatch Logs connectivity */ async function testAwsConnection(): Promise { try { // Initialize AWS service const awsService = new AwsService(); // Test connection const result = await awsService.testConnection(); // Handle result based on success/failure if (result.success) { handleSuccessResult(result); } else { handleFailureResult(result); } } catch (error) { logger.error('Unexpected error during AWS connection test:', error); } } // Run the test testAwsConnection().catch(err => logger.error('Unhandled error:', err));