Repository: getmoto/moto

Issue:
Account ID is 10 instead of 12 digits?
Staring at examples like this: https://github.com/spulec/moto/blob/master/moto/ssm/utils.py

I can see that we're using 10 digit account IDs, but AWS use 12 digit account IDs... which makes any ARN regex matching not work.

Am I missing something obvious here? (like we do this for a good reason that isn't mentioned in the doco/anywhere)?


Discussion:
Hey @michael-robbins, thanks for raising this.

All services should be using the same centralized accountID that's defined here: https://github.com/spulec/moto/blob/master/moto/core/models.py#L32
That was only introduced relatively recently though, so not all services have been refactored to use it yet.

Do you have any other examples of rogue account IDs?
Just doing a cursory search seems the one I cared about is one of the 'few' left to migrate: https://github.com/spulec/moto/search?q=1234567890

Resolving patch:
diff --git a/moto/rds2/models.py b/moto/rds2/models.py
--- a/moto/rds2/models.py
+++ b/moto/rds2/models.py
@@ -151,8 +151,8 @@ def __init__(self, **kwargs):
 
     @property
     def db_instance_arn(self):
-        return "arn:aws:rds:{0}:1234567890:db:{1}".format(
-            self.region, self.db_instance_identifier
+        return "arn:aws:rds:{0}:{1}:db:{2}".format(
+            self.region, ACCOUNT_ID, self.db_instance_identifier
         )
 
     @property
@@ -551,8 +551,8 @@ def __init__(self, database, snapshot_id, tags):
 
     @property
     def snapshot_arn(self):
-        return "arn:aws:rds:{0}:1234567890:snapshot:{1}".format(
-            self.database.region, self.snapshot_id
+        return "arn:aws:rds:{0}:{1}:snapshot:{2}".format(
+            self.database.region, ACCOUNT_ID, self.snapshot_id
         )
 
     def to_xml(self):
@@ -614,7 +614,7 @@ def __init__(self, group_name, description, tags):
         self.ip_ranges = []
         self.ec2_security_groups = []
         self.tags = tags
-        self.owner_id = "1234567890"
+        self.owner_id = ACCOUNT_ID
         self.vpc_id = None
 
     def to_xml(self):
diff --git a/moto/secretsmanager/utils.py b/moto/secretsmanager/utils.py
--- a/moto/secretsmanager/utils.py
+++ b/moto/secretsmanager/utils.py
@@ -5,6 +5,8 @@
 import six
 import re
 
+from moto.core import ACCOUNT_ID
+
 
 def random_password(
     password_length,
@@ -68,8 +70,8 @@ def random_password(
 
 def secret_arn(region, secret_id):
     id_string = "".join(random.choice(string.ascii_letters) for _ in range(5))
-    return "arn:aws:secretsmanager:{0}:1234567890:secret:{1}-{2}".format(
-        region, secret_id, id_string
+    return "arn:aws:secretsmanager:{0}:{1}:secret:{2}-{3}".format(
+        region, ACCOUNT_ID, secret_id, id_string
     )
 
 
diff --git a/moto/ssm/utils.py b/moto/ssm/utils.py
--- a/moto/ssm/utils.py
+++ b/moto/ssm/utils.py
@@ -1,4 +1,4 @@
-ACCOUNT_ID = "1234567890"
+from moto.core import ACCOUNT_ID
 
 
 def parameter_arn(region, parameter_name):


Test patch:
diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py
--- a/tests/test_rds2/test_rds2.py
+++ b/tests/test_rds2/test_rds2.py
@@ -31,7 +31,7 @@ def test_create_database():
     db_instance["MasterUsername"].should.equal("root")
     db_instance["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("my_sg")
     db_instance["DBInstanceArn"].should.equal(
-        "arn:aws:rds:us-west-2:1234567890:db:db-master-1"
+        "arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID)
     )
     db_instance["DBInstanceStatus"].should.equal("available")
     db_instance["DBName"].should.equal("staging-postgres")
@@ -312,7 +312,7 @@ def test_get_databases():
     list(instances["DBInstances"]).should.have.length_of(1)
     instances["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-master-1")
     instances["DBInstances"][0]["DBInstanceArn"].should.equal(
-        "arn:aws:rds:us-west-2:1234567890:db:db-master-1"
+        "arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID)
     )
 
 
diff --git a/tests/test_secretsmanager/test_secretsmanager.py b/tests/test_secretsmanager/test_secretsmanager.py
--- a/tests/test_secretsmanager/test_secretsmanager.py
+++ b/tests/test_secretsmanager/test_secretsmanager.py
@@ -4,6 +4,7 @@
 import boto3
 
 from moto import mock_secretsmanager, mock_lambda, settings
+from moto.core import ACCOUNT_ID
 from botocore.exceptions import ClientError
 import string
 import pytz
@@ -30,11 +31,15 @@ def test_get_secret_value():
 def test_get_secret_value_by_arn():
     conn = boto3.client("secretsmanager", region_name="us-west-2")
 
+    name = "java-util-test-password"
     secret_value = "test_get_secret_value_by_arn"
-    result = conn.create_secret(
-        Name="java-util-test-password", SecretString=secret_value
+    result = conn.create_secret(Name=name, SecretString=secret_value)
+    arn = result["ARN"]
+    arn.should.match(
+        "^arn:aws:secretsmanager:us-west-2:{}:secret:{}".format(ACCOUNT_ID, name)
     )
-    result = conn.get_secret_value(SecretId=result["ARN"])
+
+    result = conn.get_secret_value(SecretId=arn)
     assert result["SecretString"] == secret_value
 
 
diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py
--- a/tests/test_ssm/test_ssm_boto3.py
+++ b/tests/test_ssm/test_ssm_boto3.py
@@ -12,6 +12,7 @@
 import pytest
 
 from moto import mock_ec2, mock_ssm
+from moto.core import ACCOUNT_ID
 from moto.ssm.models import PARAMETER_VERSION_LIMIT, PARAMETER_HISTORY_MAX_RESULTS
 from tests import EXAMPLE_AMI_ID
 
@@ -120,8 +121,8 @@ def test_get_parameters_by_path():
     {p["ARN"] for p in response["Parameters"]}.should.equal(
         set(
             [
-                "arn:aws:ssm:us-east-1:1234567890:parameter/foo",
-                "arn:aws:ssm:us-east-1:1234567890:parameter/baz",
+                "arn:aws:ssm:us-east-1:{}:parameter/foo".format(ACCOUNT_ID),
+                "arn:aws:ssm:us-east-1:{}:parameter/baz".format(ACCOUNT_ID),
             ]
         )
     )
@@ -247,7 +248,7 @@ def test_put_parameter(name):
     response["Parameters"][0]["Version"].should.equal(1)
     response["Parameters"][0]["LastModifiedDate"].should.be.a(datetime.datetime)
     response["Parameters"][0]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name)
+        "arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name)
     )
     initial_modification_date = response["Parameters"][0]["LastModifiedDate"]
 
@@ -274,7 +275,7 @@ def test_put_parameter(name):
         initial_modification_date
     )
     response["Parameters"][0]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name)
+        "arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name)
     )
 
     response = client.put_parameter(
@@ -295,7 +296,7 @@ def test_put_parameter(name):
         initial_modification_date
     )
     response["Parameters"][0]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name)
+        "arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name)
     )
 
 
@@ -408,7 +409,7 @@ def test_get_parameter():
     response["Parameter"]["Type"].should.equal("String")
     response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
     response["Parameter"]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/test"
+        "arn:aws:ssm:us-east-1:{}:parameter/test".format(ACCOUNT_ID)
     )
 
 
@@ -434,7 +435,7 @@ def test_get_parameter_with_version_and_labels():
     response["Parameter"]["Type"].should.equal("String")
     response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
     response["Parameter"]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/test-1"
+        "arn:aws:ssm:us-east-1:{}:parameter/test-1".format(ACCOUNT_ID)
     )
 
     response = client.get_parameter(Name="test-2:1", WithDecryption=False)
@@ -443,7 +444,7 @@ def test_get_parameter_with_version_and_labels():
     response["Parameter"]["Type"].should.equal("String")
     response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
     response["Parameter"]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/test-2"
+        "arn:aws:ssm:us-east-1:{}:parameter/test-2".format(ACCOUNT_ID)
     )
 
     response = client.get_parameter(Name="test-2:test-label", WithDecryption=False)
@@ -452,7 +453,7 @@ def test_get_parameter_with_version_and_labels():
     response["Parameter"]["Type"].should.equal("String")
     response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
     response["Parameter"]["ARN"].should.equal(
-        "arn:aws:ssm:us-east-1:1234567890:parameter/test-2"
+        "arn:aws:ssm:us-east-1:{}:parameter/test-2".format(ACCOUNT_ID)
     )
 
     with pytest.raises(ClientError) as ex: