Repository: getmoto/moto
Pull request #6560 (2023-07-25 01:20:48)

[Bug fix] Add required deduplication_id parameter to sns:PublishBatch
This fixes a bug when publishing to an SNS FifoTopic. Currently any message published to a FifoTopic results in the following error:

> The topic should either have ContentBasedDeduplication enabled or MessageDeduplicationId provided explicitly


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/getmoto/moto/pull/6560?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) Report
> Merging [#6560](https://app.codecov.io/gh/getmoto/moto/pull/6560?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) (93e281b) into [master](https://app.codecov.io/gh/getmoto/moto/commit/1670471068cb3e4686e406812ccbedd1781702ac?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) (1670471) will **increase** coverage by `0.00%`.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #6560   +/-   ##
=======================================
  Coverage   96.18%   96.18%           
=======================================
  Files         800      800           
  Lines       78708    78708           
=======================================
+ Hits        75704    75707    +3     
+ Misses       3004     3001    -3     
```

| Flag | Coverage Δ | |
|---|---|---|
| servertests | `36.84% <ø> (ø)` | |
| unittests | `96.13% <ø> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Files Changed](https://app.codecov.io/gh/getmoto/moto/pull/6560?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | Coverage Δ | |
|---|---|---|
| [moto/sns/models.py](https://app.codecov.io/gh/getmoto/moto/pull/6560?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto#diff-bW90by9zbnMvbW9kZWxzLnB5) | `97.29% <ø> (ø)` | |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/getmoto/moto/pull/6560/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto)



Patch:
diff --git a/moto/ec2/models/managed_prefixes.py b/moto/ec2/models/managed_prefixes.py
index eb2f90898..35f6326f4 100644
--- a/moto/ec2/models/managed_prefixes.py
+++ b/moto/ec2/models/managed_prefixes.py
@@ -135,36 +135,80 @@ class ManagedPrefixListBackend:
         managed_pl.state = "modify-complete"
         return managed_pl
 
-    def create_default_pls(self) -> None:
-        entry = [
-            {"Cidr": "52.216.0.0/15", "Description": "default"},
-            {"Cidr": "3.5.0.0/19", "Description": "default"},
-            {"Cidr": "54.231.0.0/16", "Description": "default"},
-        ]
-
+    def _create_aws_managed_prefix_list(
+        self, name: str, address_family: str, entries: List[Dict[str, str]]
+    ) -> None:
         managed_prefix_list = self.create_managed_prefix_list(
-            address_family="IPv4",
-            entry=entry,
-            prefix_list_name=f"com.amazonaws.{self.region_name}.s3",  # type: ignore[attr-defined]
+            address_family=address_family,
+            entry=entries,
+            prefix_list_name=name,
             owner_id="aws",
         )
         managed_prefix_list.version = None
         managed_prefix_list.max_entries = None
         self.managed_prefix_lists[managed_prefix_list.id] = managed_prefix_list
 
-        entry = [
-            {"Cidr": "3.218.182.0/24", "Description": "default"},
-            {"Cidr": "3.218.180.0/23", "Description": "default"},
-            {"Cidr": "52.94.0.0/22", "Description": "default"},
-            {"Cidr": "52.119.224.0/20", "Description": "default"},
-        ]
+    def create_default_pls(self) -> None:
+        # See https://docs.aws.amazon.com/vpc/latest/userguide/working-with-aws-managed-prefix-lists.html
 
-        managed_prefix_list = self.create_managed_prefix_list(
+        # S3
+        self._create_aws_managed_prefix_list(
+            name=f"com.amazonaws.{self.region_name}.s3",  # type: ignore[attr-defined]
             address_family="IPv4",
-            entry=entry,
-            prefix_list_name=f"com.amazonaws.{self.region_name}.dynamodb",  # type: ignore[attr-defined]
-            owner_id="aws",
+            entries=[
+                {"Cidr": "52.216.0.0/15", "Description": "default"},
+                {"Cidr": "3.5.0.0/19", "Description": "default"},
+                {"Cidr": "54.231.0.0/16", "Description": "default"},
+            ],
+        )
+
+        # DynamoDB
+        self._create_aws_managed_prefix_list(
+            name=f"com.amazonaws.{self.region_name}.dynamodb",  # type: ignore[attr-defined]
+            address_family="IPv4",
+            entries=[
+                {"Cidr": "3.218.182.0/24", "Description": "default"},
+                {"Cidr": "3.218.180.0/23", "Description": "default"},
+                {"Cidr": "52.94.0.0/22", "Description": "default"},
+                {"Cidr": "52.119.224.0/20", "Description": "default"},
+            ],
+        )
+
+        # CloudFront
+        self._create_aws_managed_prefix_list(
+            name="com.amazonaws.global.cloudfront.origin-facing",
+            address_family="IPv4",
+            entries=[
+                {"Cidr": "13.124.199.0/24", "Description": "default"},
+                {"Cidr": "130.176.0.0/18", "Description": "default"},
+                {"Cidr": "15.158.0.0/16", "Description": "default"},
+                {"Cidr": "18.68.0.0/16", "Description": "default"},
+                {"Cidr": "204.246.166.0/24", "Description": "default"},
+                {"Cidr": "205.251.218.0/24", "Description": "default"},
+                {"Cidr": "3.172.0.0/18", "Description": "default"},
+                {"Cidr": "54.239.208.0/21", "Description": "default"},
+                {"Cidr": "64.252.64.0/18", "Description": "default"},
+                {"Cidr": "70.132.0.0/18", "Description": "default"},
+            ],
+        )
+
+        # Ground Station
+        self._create_aws_managed_prefix_list(
+            name="com.amazonaws.global.groundstation",
+            address_family="IPv4",
+            entries=[{"Cidr": "3.2.16.0/20", "Description": "default"}],
+        )
+
+        # VPC Lattice
+        self._create_aws_managed_prefix_list(
+            name=f"com.amazonaws.{self.region_name}.vpc-lattice",  # type: ignore[attr-defined]
+            address_family="IPv4",
+            entries=[{"Cidr": "169.254.171.0/24", "Description": "default"}],
+        )
+
+        # VPC Lattice ipv6
+        self._create_aws_managed_prefix_list(
+            name=f"com.amazonaws.{self.region_name}.ipv6.vpc-lattice",  # type: ignore[attr-defined]
+            address_family="IPv6",
+            entries=[{"Cidr": "fd00:ec2:80::/64", "Description": "default"}],
         )
-        managed_prefix_list.version = None
-        managed_prefix_list.max_entries = None
-        self.managed_prefix_lists[managed_prefix_list.id] = managed_prefix_list
diff --git a/moto/sns/models.py b/moto/sns/models.py
index 2c77cfa30..c707b0500 100644
--- a/moto/sns/models.py
+++ b/moto/sns/models.py
@@ -1043,6 +1043,7 @@ class SNSBackend(BaseBackend):
                     subject=entry.get("Subject"),
                     message_attributes=entry.get("MessageAttributes", {}),
                     group_id=entry.get("MessageGroupId"),
+                    deduplication_id=entry.get("MessageDeduplicationId"),
                 )
                 successful.append({"MessageId": message_id, "Id": entry["Id"]})
             except Exception as e:


Test patch:
diff --git a/tests/test_ec2/test_prefix_lists.py b/tests/test_ec2/test_prefix_lists.py
index 2d48e82fe..27783f661 100644
--- a/tests/test_ec2/test_prefix_lists.py
+++ b/tests/test_ec2/test_prefix_lists.py
@@ -177,14 +177,14 @@ def test_describe_prefix_lists():
     ec2 = boto3.client("ec2", region_name="us-west-1")
 
     default_lists = ec2.describe_prefix_lists()["PrefixLists"]
-    assert len(default_lists) == 2
+    assert len(default_lists) == 6
 
     ec2.create_managed_prefix_list(
         PrefixListName="examplelist", MaxEntries=2, AddressFamily="?"
     )
 
     all_lists = ec2.describe_prefix_lists()["PrefixLists"]
-    assert len(all_lists) == 2
+    assert len(all_lists) == 6
     for pl in all_lists:
         assert "com.amazonaws" in pl["PrefixListName"]