async function sendAnonymousUsage()

in source/custom-resource/index.js [62:93]


async function sendAnonymousUsage(properties) {
  const METRICS_ENDPOINT = 'https://metrics.awssolutionsbuilder.com/generic';
  const { SOLUTION_ID, UUID, VERSION, TYPE, SEND_METRICS } = properties;

  if (SEND_METRICS === 'true') {
    const config = {
      headers: {
        'Content-Type': 'application/json'
      }
    };
    const data = {
      Solution: SOLUTION_ID,
      TimeStamp: `${new Date().toISOString().replace(/T/, ' ')}`,
      UUID: UUID,
      Version: VERSION,
      Data: {
        Region: process.env.AWS_REGION,
        Type: TYPE
      }
    };

    try {
      await axios.post(METRICS_ENDPOINT, data, config);
      return { Message: 'Anonymous data was sent successfully.' };
    } catch (error) {
      console.error('Error to send anonymous usage.');
      return { Message: 'Anonymous data was sent failed.' };
    }
  } else {
    return { Message: 'Anonymous data was not sent.' };
  }
}