diff --git a/moto/ec2/exceptions.py b/moto/ec2/exceptions.py index d32118b82..e5432baf7 100644 --- a/moto/ec2/exceptions.py +++ b/moto/ec2/exceptions.py @@ -156,6 +156,14 @@ class InvalidPermissionNotFoundError(EC2ClientError): "The specified rule does not exist in this security group") +class InvalidPermissionDuplicateError(EC2ClientError): + + def __init__(self): + super(InvalidPermissionDuplicateError, self).__init__( + "InvalidPermission.Duplicate", + "The specified rule already exists") + + class InvalidRouteTableIdError(EC2ClientError): def __init__(self, route_table_id): diff --git a/moto/ec2/models.py b/moto/ec2/models.py index a0a4c93f1..989ec5572 100755 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -35,6 +35,7 @@ from .exceptions import ( InvalidSecurityGroupDuplicateError, InvalidSecurityGroupNotFoundError, InvalidPermissionNotFoundError, + InvalidPermissionDuplicateError, InvalidRouteTableIdError, InvalidRouteError, InvalidInstanceIdError, @@ -1311,7 +1312,7 @@ class SecurityGroup(TaggedEC2Resource): def add_ingress_rule(self, rule): if rule in self.ingress_rules: - raise InvalidParameterValueError('security_group') + raise InvalidPermissionDuplicateError() else: self.ingress_rules.append(rule)