Scenario thi: Use Message Filter feature của SNS để enable subscribers to SNS topic receive only a subset of topic messages.
Ví dụ: Insurance quote application
Giải pháp: Use fanout message pattern using SNS and SQS to decouple website from backend systems.
{
"eventType": ["order_placed"],
"amount": [{"numeric": [">=", 100]}],
"store": [{"prefix": "us-"}]
}
Lợi ích:
| Operator | Ví dụ |
|---|---|
| Exact match | ["order_placed"] |
| Prefix | [{"prefix": "us-"}] |
| Numeric | [{"numeric": [">=", 100]}] |
| Anything-but | [{"anything-but": ["test"]}] |
| Exists | [{"exists": true}] |
Without: SNS → SQS → Lambda (processes ALL messages, discards 90%)
With: SNS → Filter → SQS → Lambda (processes only relevant 10%)
Benefits:
{
"source": ["my-app"],
"detail-type": ["OrderCreated"],
"detail": {
"amount": [{"numeric": [">", 100]}],
"region": ["us-east-1", "eu-west-1"]
}
}
Insurance Application:
Quote Request → SNS Topic
│
├── Filter: {"type": ["new_policy"]} → SQS → Sales Lambda
│
└── Filter: {"type": ["quote"]} → SQS → Analytics Lambda
Exam Tip: