async function emitNewMetric()

in workmail-stop-mail-storm/src/app.js [9:34]


async function emitNewMetric(protectedRecipients) {
    // see https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricData.html for detailed
    // explanation of the parameters
    const params = {
        Namespace: 'WorkMail',
        MetricData: protectedRecipients.map(protectedRecipient =>
            ({
                MetricName: 'EmailsReceived',
                Dimensions: [
                    {
                        Name: 'EmailAddress',
                        Value: protectedRecipient
                    }
                ],
                Unit: 'Count',
                Value: 1
            }))
    };

    // it is important that we emit the metric even if we block this sending later
    // otherwise, the alarm would clear after 5 mins, people would be able to continue the storm for a while again
    // that would lead to a on-off-on-off pattern, which still lets too much junk through

    await cloudwatch.putMetricData(params).promise();
    console.log('Finished putMetricData');
}