DataDog Event Writer

Overview

This event writer picks up events from SNS queues and writes them to relevant DataDog dashboards.

Any application that wants to post a metric to Datadog would post the metric payload onto the sns-euw1-${env}-digital-storepick-events TOPIC thus allowing asynchronous way of posting metric to Datadog.

This Lambda has generic functionality of extracting the matrices from events posted in SNS and further posting them onto DataDog. It uses custom built code to do so.

An example event is shown in Code section below.

It is being used by multiple repositories in Storepick. You will not find this lambda in serverless.yaml of individual repos as it need not be called in the Step functions. It stays in the background and does the job based on events generated by actual code.

Dependencies

SSM Attribute

See SSM Key

Code

lambdas.storepick_event_writer.lambda_handler(event, context)[source]

This Lambda is trigerred by env specific digital-storepick-events topic. Any application that wants to post a metric to Datadog would post the metric payload onto the digital-storepick-events topic thus allowing asynchronous way of posting metric to Datadog.

The following information needs to be in the event which is important for the Datadog dashboard:
  • Metric Name - Name of metric to be posted

  • Metric Type - Type of metric e.g. count, sum

  • Metric Value - Actual value of the metric

  • Application Name - Metric relates to which application e.g. nhs_discount

Parameters

event (dict) – event[‘Records’][0][‘Sns’].get(“Message”)

Example

event = {
    "Records": [
        {
            "EventVersion": "1.0",
            "EventSubscriptionArn": "arn:aws:sns:us-east-2:123456789012:sns-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
            "EventSource": "aws:sns",
            "Sns": {
                "SignatureVersion": "1",
                "Timestamp": "2019-01-02T12:45:07.000Z",
                "Signature": "tcc6faL2yUC6dgZdmrwh1Y4cGa/ebXEkAi6RibDsvpi+tE/1+82j...65r==",
                "SigningCertUrl": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-ac565b8b1a6c5d002d285f9598aa1d9b.pem",
                "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
                "Message": "{"eventType": "writeMetricForMonitoring", "eventData": { "name": "storepick_state_mc2","type": "check","metric_value": "2", "application": "nhs-discount" } }",
                "MessageAttributes": {
                    "eventType": {
                        "Type": "String",
                        "Value": "logRowToBq"
                    }
                },
                "Type": "Notification",
                "UnsubscribeUrl": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:123456789012:test-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
                "TopicArn": "arn:aws:sns:us-east-2:123456789012:sns-lambda",
                "Subject": "TestInvoke"
            }
        }
    ]
}
Returns

response from datadog api call

Return type

event (dict)

Example

event = {'status': 'ok'}
Raises

Exception – Exception containing details about exception