AWS SNS(Amazon Simple Notification Service)的订阅过滤策略有一些限制。以下是一些解决方法和代码示例:
import boto3
sns = boto3.client('sns')
# 创建一个订阅,指定多个过滤条件
response = sns.subscribe(
TopicArn='arn:aws:sns:us-west-2:123456789012:MyTopic',
Protocol='email',
Endpoint='example@example.com',
Attributes={
'FilterPolicy': json.dumps({
'store': ['example_corp'],
'event': ['order_placed', 'order_cancelled']
})
}
)
import boto3
sns = boto3.client('sns')
# 创建一个订阅,使用通配符筛选条件
response = sns.subscribe(
TopicArn='arn:aws:sns:us-west-2:123456789012:MyTopic',
Protocol='email',
Endpoint='example@example.com',
Attributes={
'FilterPolicy': json.dumps({
'store': ['example_*'],
'event': ['order_*']
})
}
)
import boto3
sns = boto3.client('sns')
# 创建一个订阅,使用字符串比较运算符筛选条件
response = sns.subscribe(
TopicArn='arn:aws:sns:us-west-2:123456789012:MyTopic',
Protocol='email',
Endpoint='example@example.com',
Attributes={
'FilterPolicy': json.dumps({
'store': [{
'prefix': 'example_'
}],
'event': [{
'prefix': 'order_'
}]
})
}
)
这些解决方法可以帮助您限制AWS SNS订阅过滤策略的条件,并根据您的需求进行适当的更改和修改。