I am trying to publish to sns topic but have been hit by this error multiple times.
This happen when i have already subscribe and I use FilterPolicy.
There seems to be an error when create_sqs_message_attributes
, if there is FilterPolicy
Subscription Attribute
{
"Attributes": {
"TopicArn": "arn:aws:sns:ap-southeast-1:000000000000:topups_local-dev-topic",
"Endpoint": "arn:aws:sqs:ap-southeast-1:000000000000:topups_local-dev_create_transaction",
"Protocol": "sqs",
"SubscriptionArn": "arn:aws:sns:ap-southeast-1:000000000000:topups_local-dev-topic:fccf4f00-3d2a-4385-b6d4-4bc91e2dbcd1",
"PendingConfirmation": "false",
"Owner": "000000000000",
"RawMessageDelivery": "True",
"FilterPolicy": "{\"x-xsh-action\":[\"create_transaction\"]}",
"ConfirmationWasAuthenticated": "true",
"FilterPolicyScope": "MessageAttributes"
}
}
What is being publish
{
TopicArn: 'arn:aws:sns:ap-southeast-1:000000000000:topups_local-dev-topic',
Message: '{"id":"123"}',
MessageAttributes: {
'x-xsh-action': { DataType: 'String', StringValue: 'create_transaction' }
}
}
The Error
2023-04-14T06:15:55.136 ERROR --- [ sns_pub_0] l.services.sns.publisher : An internal error occurred while trying to format the message for SQS
Traceback (most recent call last):
File "/opt/code/localstack/localstack/services/sns/publisher.py", line 251, in _publish
sqs_message_attrs = self.create_sqs_message_attributes(
File "/opt/code/localstack/localstack/services/sns/publisher.py", line 311, in create_sqs_message_attributes
attribute["BinaryValue"] = base64.b64decode(to_bytes(val))
File "/usr/local/lib/python3.10/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding