0.0.1-beta-4 • Published 2 years ago

spark-v3-sns-publisher v0.0.1-beta-4

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
2 years ago

✳️ SPARK v3 SNS PUBLISHER ✳️

SNS Publisher Lambda handler for DynamoDB Streams

➡️ The fox-write-api-v3 writes items to Spark DynamoDB Tables which trigger DynamoDB Streams, which in turn triggers our SNS Publisher Lambda in order to send SNS requests to its corresponding SNS topic.

Example DynamoDB Stream Payload:

{
  "Records": [
    {
      "eventID": "fe981bbed304aaa4e666c0ecdc2f6666",
      "eventName": "INSERT",
      "eventVersion": "1.1",
      "eventSource": "aws:dynamodb",
      "awsRegion": "us-east-1",
      "dynamodb": {
        "ApproximateCreationDateTime": 1576516897,
        "Keys": {
          "sk": {
            "S": "sk"
          },
          "pk": {
            "S": "pk"
          }
        },
        "NewImage": {...},
        "SequenceNumber": "125319600000000013310543218",
        "SizeBytes": 200,
        "StreamViewType": "NEW_IMAGE"
      },
      "eventSourceARN": "arn:aws:dynamodb:us-east-1:1234567890:table/my-test-table/stream/2021-12-02T00:00:00.000"
    }
  ]
}

Request Class

➡️ The Request Class:

  1. Takes the DynamoDB Stream
  2. Unmarshall the stream data.
  3. Filter out requests dependent on CMS Editorial workflow.
  4. Properly set payload to be sent to the SNS topic.

Example SNS Request Payload

{
  "TopicArn": "arn:aws:sns:us-east-1:456757977883:v3",
  "Message": {
    "action": "INSERT",
    "data": {
      "id": "254a9cf9-dd9d-4a43-8d64-6a34a0d1dc06",
      "post_status": "publish",
      "thumbnail": null,
      ...,
      ...,
      ...,
      "content_type": "spark_post",
      "share": ["FNC"],
      "spark_id": "254a9cf9-dd9d-4a43-8d64-6a34a0d1dc06",
      "original_shared_post": {
        "original_published_date": "2022-07-08T09:15:51.238Z",
        "original_received_date": "2022-07-08T09:15:51.238Z",
        "original_network": "FW",
        "original_external_post_type": "",
        "original_canonical_url": "foxweather.com/automated-synergy/debitis-veniam-nulla",
        "original_modified_date": "2022-07-08T09:15:51.238Z",
        "original_spark_id": "254a9cf9-dd9d-4a43-8d64-6a34a0d1dc06",
        "original_post_id": "0",
        "original_post_uuidv5": "254a9cf9-dd9d-4a43-8d64-6a34a0d1dc06",
        "original_post_type": "",
        "original_post_status": "publish",
        "original_share_date": "2022-07-08T09:15:51.238Z",
        "original_post_share": ["FNC"]
      }
    }
  }
}