Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix: SNS Subscribe now applies Attributes (RawMessageDelivery, FilterPolicy) (#71)
Santiago Doldánb515551267fe
diff --git a/ministack/services/sns.py b/ministack/services/sns.pyindex 66ff2f1c..50f06bdb 100644--- a/ministack/services/sns.py+++ b/ministack/services/sns.py@@ -219,6 +219,13 @@ def _subscribe(params):},}+ i = 1+ while _p(params, f"Attributes.entry.{i}.key"):+ key = _p(params, f"Attributes.entry.{i}.key")+ val = _p(params, f"Attributes.entry.{i}.value")+ sub["attributes"][key] = val+ i += 1+topic["subscriptions"].append(sub)_sub_arn_to_topic[sub_arn] = topic_arn_refresh_subscription_counts(topic)diff --git a/tests/test_services.py b/tests/test_services.pyindex 95eb827c..a974cb07 100644--- a/tests/test_services.py+++ b/tests/test_services.py@@ -1265,6 +1265,48 @@ def test_sns_subscription_attributes(sns):assert resp["Attributes"]["RawMessageDelivery"] == "true"+def test_sns_subscribe_with_attributes(sns):+ arn = sns.create_topic(Name="intg-sns-subwithattr")["TopicArn"]+ sub = sns.subscribe(+ TopicArn=arn,+ Protocol="sqs",+ Endpoint="arn:aws:sqs:us-east-1:000000000000:intg-sns-subwithattr-q",+ Attributes={+ "RawMessageDelivery": "true",+ "FilterPolicy": json.dumps({"event": ["OrderCreated"]}),+ },+ )+ sub_arn = sub["SubscriptionArn"]+ resp = sns.get_subscription_attributes(SubscriptionArn=sub_arn)+ assert resp["Attributes"]["RawMessageDelivery"] == "true"+ assert json.loads(resp["Attributes"]["FilterPolicy"]) == {"event": ["OrderCreated"]}+++def test_sns_sqs_fanout_raw_message_delivery(sns, sqs):+ topic_arn = sns.create_topic(Name="intg-sns-fanout-raw")["TopicArn"]+ q_url = sqs.create_queue(QueueName="intg-sns-fanout-raw-q")["QueueUrl"]+ q_arn = sqs.get_queue_attributes(+ QueueUrl=q_url,+ AttributeNames=["QueueArn"],+ )["Attributes"]["QueueArn"]++ sns.subscribe(+ TopicArn=topic_arn,+ Protocol="sqs",+ Endpoint=q_arn,+ Attributes={"RawMessageDelivery": "true"},+ )+ sns.publish(TopicArn=topic_arn, Message="raw fanout msg")++ msgs = sqs.receive_message(+ QueueUrl=q_url,+ MaxNumberOfMessages=1,+ WaitTimeSeconds=1,+ )+ assert len(msgs.get("Messages", [])) == 1+ assert msgs["Messages"][0]["Body"] == "raw fanout msg"++def test_sns_publish_batch(sns):arn = sns.create_topic(Name="intg-sns-batch")["TopicArn"]resp = sns.publish_batch(