triggermesh / aws-event-sources

Knative event sources for AWS services
Apache License 2.0
60 stars 14 forks source link

sqs: Propagate message attrs to CloudEvents context #336

Closed antoineco closed 3 years ago

antoineco commented 3 years ago

Closes #335

Based on my example at https://github.com/triggermesh/aws-event-sources/issues/330#issuecomment-924062007:

image

Notice how the CloudEvents extensions are based on the attributes of the SQS message:

☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: com.amazon.sqs.message
  source: arn:aws:sqs:us-west-1:123456789012:test
  id: 4c7e252c-88dd-4ae0-9bdc-9a95a70256ff
  time: 2021-09-21T23:08:10.5150431Z
  datacontenttype: application/json
Extensions,
  sqsmsganattribute: The value of An-Attribute
  sqsmsgotherattribute: 3.333333333
Data,
  {
    "Attributes": {
      "ApproximateFirstReceiveTimestamp": "1632265687391",
      "ApproximateReceiveCount": "1",
      "SenderId": "AIDAQUHRFMYWSR2PNVTVZ",
      "SentTimestamp": "1632265687380"
    },
    "Body": "{\"msg\": \"Hello, World!\"}",
    "MD5OfBody": "fa00cf89134387aaa0cd442076e26673",
    "MD5OfMessageAttributes": "23f4a611a378aa04a1bb82d276accb76",
    "MessageAttributes": {
      "An-Attribute": {
        "BinaryListValues": null,
        "BinaryValue": null,
        "DataType": "String.Foo",
        "StringListValues": null,
        "StringValue": "The value of An-Attribute"
      },
      "Other_Attribute": {
        "BinaryListValues": null,
        "BinaryValue": null,
        "DataType": "Number.Bar",
        "StringListValues": null,
        "StringValue": "3.333333333"
      }
    },
    "MessageId": "4c7e252c-88dd-4ae0-9bdc-9a95a70256ff",
    "ReceiptHandle": "AQEBCjJegqUDdZRi3FayTIo6GrnxY9CUGPuZXVF4zyyC+akUyKTwf0JC+b+qEWzQCMhDk0GmRmu+x0Gn7n9aiJRfSYFCTBk6qJM8ecT7kBnYGmaxQja56P4bUxPKvcI++01MhLQaHHwYFzevzbIYwHrLGmLScFw7IIuS3LD8qUEWxBphAIJi6zboWcU81ylCWvp7i+7ESzDUZQothuV5xebC5xXCSGAsGvkr75JzilUWJnQ9hH/bCGURol0Z4W88OSRTfyuImx1YGYjdMIsl0tunXdkyjQorRJ4EKWSSnKC3A4okLbh/hVvh+/FsX+ZiWNaRL7vjP+l7IrxnUNy2fzdqa1d3uC2N9ztfGRONUgOIJQvkJMc4MmRISueHumlJ/Iyj"
  }