import AWS from 'aws-sdk' import { URLs } from './types' AWS.config.update({ region: 'ap-southeast-2' }) const sns = new AWS.SNS() export const getServiceUrls = ( service: string, environment?: string, ): URLs => { const url = `service.${service}.${environment ? `${environment}.` : ''}mybest.health` return { httpUrl: `https://${url}`, awsUrl: url, service, friendlyUrl: `${service} ${environment || 'prod'}`, } } export const sendSnsMessage = async (friendUrls: string[]) => { try { await sns.publish({ TopicArn: process.env.SNS_TOPIC_ARN, Subject: 'my best health Oncall Notifier', Message: `The following services are down:\n\n${friendUrls.join('\n')}`, }).promise() return true } catch (err) { // eslint-disable-next-line no-console console.log(err.message) return false } }