From 366a5f594f58a55603269ddab0b09628b0c3a1d8 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 7 Nov 2023 21:48:26 -0100 Subject: [PATCH] AWSLambda: Ensure simple backend does not require docker-module (#7000) --- moto/awslambda/models.py | 9 +++++++-- setup.cfg | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py index b1060d578..a6e4a11a6 100644 --- a/moto/awslambda/models.py +++ b/moto/awslambda/models.py @@ -7,8 +7,6 @@ from gzip import GzipFile from typing import Any, Dict, Iterable, List, Optional, Tuple, Union from sys import platform -import docker -import docker.errors import hashlib import io import logging @@ -157,6 +155,8 @@ class _DockerDataVolumeContext: with self.__class__._lock: self._vol_ref.refcount -= 1 # type: ignore[union-attr] if self._vol_ref.refcount == 0: # type: ignore[union-attr] + import docker.errors + try: self._vol_ref.volume.remove() # type: ignore[union-attr] except docker.errors.APIError as e: @@ -240,6 +240,8 @@ class _DockerDataVolumeLayerContext: with self.__class__._lock: self._vol_ref.refcount -= 1 # type: ignore[union-attr] if self._vol_ref.refcount == 0: # type: ignore[union-attr] + import docker.errors + try: self._vol_ref.volume.remove() # type: ignore[union-attr] except docker.errors.APIError as e: @@ -857,6 +859,9 @@ class LambdaFunction(CloudFormationModel, DockerModel): return s def _invoke_lambda(self, event: Optional[str] = None) -> Tuple[str, bool, str]: + import docker + import docker.errors + # Create the LogGroup if necessary, to write the result to self.logs_backend.ensure_log_group(self.logs_group_name) # TODO: context not yet implemented diff --git a/setup.cfg b/setup.cfg index 323c81606..ae691bb29 100644 --- a/setup.cfg +++ b/setup.cfg @@ -102,6 +102,7 @@ appsync = graphql-core athena = autoscaling = awslambda = docker>=3.0.0 +awslambda_simple = batch = docker>=3.0.0 batch_simple = budgets =