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): keep the tags given to CreateTopic (#1974)
iot-rocket1e8700ef4297
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 14eb427f..ed565ffc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]+### Fixed++- **SNS — `CreateTopic` keeps its tags** — the handler read `Tag.member.N` where the API sends `Tags.member.N`, so tags given at creation were dropped. Contributed by @iot-rocket.+## [1.5.21] — 2026-10-03### Addeddiff --git a/ministack/services/sns.py b/ministack/services/sns.pyindex b4ec96e2..2bd32a5d 100644--- a/ministack/services/sns.py+++ b/ministack/services/sns.py@@ -432,13 +432,7 @@ def _create_topic(params):topic["dedup_cache"] = {}topic["fifo_seq"] = 0- # Store tags from CreateTopic- i = 1- while _p(params, f"Tag.member.{i}.Key"):- key = _p(params, f"Tag.member.{i}.Key")- val = _p(params, f"Tag.member.{i}.Value")- topic["tags"][key] = val- i += 1+ topic["tags"].update(_param_tags(params))_topics[arn] = topiclogger.info("SNS topic created: %s%s", name, " (FIFO)" if is_fifo else "")@@ -1417,17 +1411,22 @@ def _list_tags_for_resource(params):f"<ListTagsForResourceResult><Tags>{tags_xml}</Tags></ListTagsForResourceResult>")+def _param_tags(params) -> dict:+ """The Tags.member.N pairs of a CreateTopic or TagResource request."""+ tags = {}+ i = 1+ while _p(params, f"Tags.member.{i}.Key"):+ tags[_p(params, f"Tags.member.{i}.Key")] = _p(params, f"Tags.member.{i}.Value")+ i += 1+ return tags++def _tag_resource(params):_arn, topic, err = _resolve_topic_tag_arn(_p(params, "ResourceArn"),"sns:TagResource")if err:return err- i = 1- while _p(params, f"Tags.member.{i}.Key"):- key = _p(params, f"Tags.member.{i}.Key")- val = _p(params, f"Tags.member.{i}.Value")- topic["tags"][key] = val- i += 1+ topic["tags"].update(_param_tags(params))return _xml(200, "TagResourceResponse", "<TagResourceResult/>")diff --git a/tests/test_sns.py b/tests/test_sns.pyindex fc975050..b6d13571 100644--- a/tests/test_sns.py+++ b/tests/test_sns.py@@ -312,6 +312,11 @@ def test_sns_tags(sns):assert tags["env"] == "staging"+def test_sns_create_topic_keeps_its_tags(sns):+ arn = sns.create_topic(Name="intg-sns-create-tags", Tags=[{"Key": "env", "Value": "dev"}])["TopicArn"]+ assert sns.list_tags_for_resource(ResourceArn=arn)["Tags"] == [{"Key": "env", "Value": "dev"}]++def test_sns_tag_resource_accepts_empty_account_topic_arn(sns):arn = sns.create_topic(Name=f"intg-sns-empty-account-{_uuid_mod.uuid4().hex[:8]}")["TopicArn"]empty_account_arn = arn.replace(":000000000000:", "::")