diff --git a/moto/opsworks/models.py b/moto/opsworks/models.py index 3adfd3323..fe8c882a7 100644 --- a/moto/opsworks/models.py +++ b/moto/opsworks/models.py @@ -422,11 +422,11 @@ class OpsWorksBackend(BaseBackend): stackid = kwargs['stack_id'] if stackid not in self.stacks: raise ResourceNotFoundException(stackid) - if name in [l.name for l in self.layers.values()]: + if name in [l.name for l in self.stacks[stackid].layers]: raise ValidationException( 'There is already a layer named "{0}" ' 'for this stack'.format(name)) - if shortname in [l.shortname for l in self.layers.values()]: + if shortname in [l.shortname for l in self.stacks[stackid].layers]: raise ValidationException( 'There is already a layer with shortname "{0}" ' 'for this stack'.format(shortname)) diff --git a/tests/test_opsworks/test_layers.py b/tests/test_opsworks/test_layers.py index 31fdeae8c..03224feb0 100644 --- a/tests/test_opsworks/test_layers.py +++ b/tests/test_opsworks/test_layers.py @@ -27,6 +27,22 @@ def test_create_layer_response(): response.should.contain("LayerId") + second_stack_id = client.create_stack( + Name="test_stack_2", + Region="us-east-1", + ServiceRoleArn="service_arn", + DefaultInstanceProfileArn="profile_arn" + )['StackId'] + + response = client.create_layer( + StackId=second_stack_id, + Type="custom", + Name="TestLayer", + Shortname="TestLayerShortName" + ) + + response.should.contain("LayerId") + # ClientError client.create_layer.when.called_with( StackId=stack_id,