Search code examples
amazon-web-servicesaws-lambdaamazon-sqsamazon-sns

AWS SNS SQS - Subscription filter policy


I would like to send messages with Subscription filter policy SNS to SQS and then to lambda.

If I apply the filter, I don't receive any message in lambda.

Here is the message:

{
  "aggregateType": "APPOINTMENT",
  "aggregateId": "4756c2b0-a579-4785-8eb2-5dae356d415b",
  "eventType": "MODIFIED",
  "eventTimestamp": "2022-04-28T08:02:03Z",
  "eventBody": {
    "createdDate": null,
    "lastModifiedDate": "2020-08-18T11:00:32.288748Z",
    "createdBy": null,
    "lastModifiedBy": "WiredUser:ds18817",
    "id": "4756c2b0-a579-4785-8eb2-5dae356d415b",
    "dealerId": "72417900_001",
    "context": "AFTERSALES",
    "type": "RESTITUTION",
    "description": "Reparación mecánica - modified",
    "dateTime": "2020-08-18T14:15:00Z",
    "origin": "RDS",
    "status": "CONCLUDED",
    "contractType": "D",
    "notificationChannels": [
      "SMS"
    ],
    "vehicle": {
      "vin": "VF1JZ0Y0E43339071",
      "brand": "RENAULT",
      "model": "SCENIC III",
      "mileage": 205000,
      "version": "SCENIC III",
      "regNumber": "2392GWR",
      "mileageUnit": "km"
    },
    "dmsId": "2786850",
    "wazyPostRequestId": null,
    "wazyPutRequestId": "a4195986-06a3-4641-80c2-081d3f83d15c",
    "customer": {
      "type": "P",
      "lastName": "RODRIGUEZ",
      "firstName": "ELENA",
      "contactPhone": "+34",
      "contactMobilePhone": "+34660211911"
    },
    "details": {
      "comments": [
        {
          "owner": "RECEPTOR",
          "number": 1,
          "comment": "REVSIAR CONTROLES\n"
        }
      ],
      "relatedObjects": [
        {
          "id": "1d058661-7edc-44e0-9a56-db632ca7e8eb",
          "type": "CONFIRMATION_SMS"
        },
        {
          "id": "2786850",
          "name": "DMS_APPT",
          "type": "DMS_APPT"
        },
        {
          "id": "2ca45b88-bc25-41c4-8e85-caf581312905",
          "name": "Reception appt",
          "type": "RECEPTION_APPT"
        },
        {
          "id": "4652290f-06bb-4b50-89a9-c635f5257af6",
          "name": "INTERVENTION_LIST",
          "type": "INTERVENTION_LIST"
        }
      ],
      "deliveryServices": [
        {
          "id": "31",
          "name": "Reparación mecánica",
          "type": "MECHANIC",
          "price": "0",
          "currency": "EUR",
          "hoursNeeded": 0.5,
          "durationNeeded": 1800.000000000
        }
      ]
    }
  }
}

Here is the Subscription filter policy:

{
  "aggregateType": [
    "APPOINTMENT"
  ],
  "eventType": [
    "MODIFIED"
  ],
  "eventbody.status": [
    "INVOICE"
  ]
}

Do you know reason why I can't receive the message with this filter, please?

Thanks for answer.


Solution

  • This is expected since the message does not match the filter. In the given message your eventbody.status="CONCLUDED", therefore does not equal to "INVOICE".

    Check the documentation about applying OR across different attributes:

    Currently, you can't use SNS filters to apply OR logic across different message attributes. Instead, you can use multiple SNS subscriptions with different endpoints to achieve the same effect. For example, assume that you have message attributes named customer_interests and customer_preferences. To apply OR logic across both attributes, create an SNS subscription to match each message attribute. Then, you can use your subscriber application to consume both types of messages through the different endpoints.

    https://docs.aws.amazon.com/sns/latest/dg/and-or-logic.html

    Greetings