From 6cf37c4b4bca18c07a850ea1e33c36ef8f1bf166 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sun, 26 Jun 2022 15:45:33 +0000 Subject: [PATCH] EBS - Defer imports until it's necessary (#5265) --- moto/ec2/models/elastic_block_store.py | 3 ++- moto/kms/models.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/moto/ec2/models/elastic_block_store.py b/moto/ec2/models/elastic_block_store.py index cc471fc21..08f784ce5 100644 --- a/moto/ec2/models/elastic_block_store.py +++ b/moto/ec2/models/elastic_block_store.py @@ -1,5 +1,4 @@ from moto.core import get_account_id, CloudFormationModel -from moto.kms import kms_backends from moto.packages.boto.ec2.blockdevicemapping import BlockDeviceType from ..exceptions import ( InvalidAMIAttributeItemValueError, @@ -404,6 +403,8 @@ class EBSBackend: # https://aws.amazon.com/kms/features/#AWS_Service_Integration # An AWS managed CMK is created automatically when you first create # an encrypted resource using an AWS service integrated with KMS. + from moto.kms import kms_backends + kms = kms_backends[self.region_name] ebs_alias = "alias/aws/ebs" if not kms.alias_exists(ebs_alias): diff --git a/moto/kms/models.py b/moto/kms/models.py index fa9e60cda..1073e980b 100644 --- a/moto/kms/models.py +++ b/moto/kms/models.py @@ -6,13 +6,13 @@ from cryptography.exceptions import InvalidSignature from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding -from moto.apigateway.exceptions import ValidationException from moto.core import get_account_id, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import get_random_hex, unix_time, BackendDict from moto.utilities.tagging_service import TaggingService from moto.core.exceptions import JsonRESTError +from .exceptions import ValidationException from .utils import ( RESERVED_ALIASES, decrypt,