Implement basic SNS message filtering (#1521)

* Add support for FilterPolicy to sns subscription set_filter_attributes

* Add basic support for sns message filtering

This adds support for exact string value matching along with AND/OR
logic as described here:

https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html

It does not provide support for:
- Anything-but string matching
- Prefix string matching
- Numeric Value Matching

The above filter policies (if configured) will not match messages.
This commit is contained in:
Iain Bullard 2018-03-21 15:49:11 +00:00 committed by Jack Danger
commit d3d9557d49
5 changed files with 194 additions and 8 deletions

View file

@ -241,6 +241,10 @@ class SNSResponse(BaseResponse):
phone_number = self._get_param('PhoneNumber')
subject = self._get_param('Subject')
message_attributes = self._get_map_prefix('MessageAttributes.entry',
key_end='Name',
value_end='Value')
if phone_number is not None:
# Check phone is correct syntax (e164)
if not is_e164(phone_number):
@ -265,7 +269,9 @@ class SNSResponse(BaseResponse):
message = self._get_param('Message')
try:
message_id = self.backend.publish(arn, message, subject=subject)
message_id = self.backend.publish(
arn, message, subject=subject,
message_attributes=message_attributes)
except ValueError as err:
error_response = self._error('InvalidParameter', str(err))
return error_response, dict(status=400)