Repository: getmoto/moto

Issue:
SES region setting is not supported
Hi,
when trying to set the region of the SES client, it seems like it is not setting the region correctly and just defaults to the global region. 
It seems like this is a bug caused in this file:
https://github.com/getmoto/moto/blob/master/moto/ses/responses.py in line 14 where the region gets set to global instead of self.region as seen here:
https://github.com/getmoto/moto/blob/master/moto/sns/responses.py on line 23.
I am currently using version 1.21.46.



Discussion:
Hi @FelixRoche, I cannot see a mention of `global` in that particular file.

Do you have a specific test case that is failing for you?
Hi @bblommers, the mention of global would be on the master branch in line 14 in the backend(self) method

I can provide some example on how it is working and how I would expect it to work on a region based service:
When verifying an email it verifies it on every region instead of the one specified in the client
My expected behavior would be only finding one identity not finding one in every region
Example code to check:

```
def test_for_email_safety(self):
        client = boto3.client("ses", region_name="eu-west-1")
        client.verify_email_identity(EmailAddress="foo@bar.com")

        regions = ["ap-northeast-1", "ap-southeast-1", "eu-central-1", "eu-west-1", "us-east-1", "us-west-2"]

        found_emails = 0

        for reg in regions:
            found_emails += len(client.list_identities().get("Identities"))

        assert found_emails == 1
```
Ah, gotcha @FelixRoche. Looks like it was never implemented as a region-based service in the first place, and even after various refactorings we kept using it as if it was a `global` service. Marking it as a bug.

Thanks for raising this!

Patch:
diff --git a/moto/ses/models.py b/moto/ses/models.py
--- a/moto/ses/models.py
+++ b/moto/ses/models.py
@@ -127,7 +127,7 @@ class SESBackend(BaseBackend):
 
         from moto.core import DEFAULT_ACCOUNT_ID
         from moto.ses import ses_backends
-        ses_backend = ses_backends[DEFAULT_ACCOUNT_ID]["global"]
+        ses_backend = ses_backends[DEFAULT_ACCOUNT_ID][region]
         messages = ses_backend.sent_messages # sent_messages is a List of Message objects
 
     Note that, as this is an internal API, the exact format may differ per versions.
@@ -602,6 +602,4 @@ def get_identity_verification_attributes(self, identities=None):
         return attributes_by_identity
 
 
-ses_backends: Mapping[str, SESBackend] = BackendDict(
-    SESBackend, "ses", use_boto3_regions=False, additional_regions=["global"]
-)
+ses_backends: Mapping[str, SESBackend] = BackendDict(SESBackend, "ses")
diff --git a/moto/ses/responses.py b/moto/ses/responses.py
--- a/moto/ses/responses.py
+++ b/moto/ses/responses.py
@@ -11,7 +11,7 @@ def __init__(self):
 
     @property
     def backend(self):
-        return ses_backends[self.current_account]["global"]
+        return ses_backends[self.current_account][self.region]
 
     def verify_email_identity(self):
         address = self.querystring.get("EmailAddress")[0]


Test patch:
diff --git a/tests/test_ses/test_ses_boto3.py b/tests/test_ses/test_ses_boto3.py
--- a/tests/test_ses/test_ses_boto3.py
+++ b/tests/test_ses/test_ses_boto3.py
@@ -19,6 +19,15 @@ def test_verify_email_identity():
     address.should.equal("test@example.com")
 
 
+@mock_ses
+def test_identities_are_region_specific():
+    us_east = boto3.client("ses", region_name="us-east-1")
+    us_east.verify_email_identity(EmailAddress="test@example.com")
+
+    us_west = boto3.client("ses", region_name="us-west-1")
+    us_west.list_identities()["Identities"].should.have.length_of(0)
+
+
 @mock_ses
 def test_verify_email_identity_idempotency():
     conn = boto3.client("ses", region_name="us-east-1")