From 182e45aa8111c7f3002bf490ebe04aaa6943cf3a Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Thu, 24 Feb 2022 23:53:43 +0000 Subject: [PATCH] Added support for custom AWS Lambda images. (#4889) --- CHANGELOG.md | 5 +++-- moto/awslambda/models.py | 4 +++- moto/settings.py | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c59f13a62..eedc3c893 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ Moto Changelog -=================== +============== 3.0.5 ----- Docker Digest for 3.0.5: - TBD + Miscellaneous: + * AWSLambda: Made the docker image repository selectable via the `MOTO_DOCKER_LAMBDA_IMAGE` environment variable. 3.0.4 ----- diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py index 4e9ae9834..458756e80 100644 --- a/moto/awslambda/models.py +++ b/moto/awslambda/models.py @@ -610,7 +610,8 @@ class LambdaFunction(CloudFormationModel, DockerModel): "host.docker.internal": "host-gateway" } - image_ref = "lambci/lambda:{}".format(self.run_time) + image_repo = settings.moto_lambda_image() + image_ref = f"{image_repo}:{self.run_time}" self.docker_client.images.pull(":".join(parse_image_ref(image_ref))) container = self.docker_client.containers.run( image_ref, @@ -1171,6 +1172,7 @@ The following environment variables are available for fine-grained control over # Note that this option will be ignored if MOTO_DOCKER_NETWORK_NAME is also set MOTO_DOCKER_NETWORK_MODE=host moto_server +The Docker image can be overridden using an environment variable: ``MOTO_DOCKER_LAMBDA_IMAGE``. .. note:: When using the decorators, a Docker container cannot reach Moto, as it does not run as a server. Any boto3-invocations used within your Lambda will try to connect to AWS. """ diff --git a/moto/settings.py b/moto/settings.py index 1927241f2..74734115a 100644 --- a/moto/settings.py +++ b/moto/settings.py @@ -66,6 +66,10 @@ def moto_server_host(): return "http://host.docker.internal" +def moto_lambda_image(): + return os.environ.get("MOTO_DOCKER_LAMBDA_IMAGE", "lambci/lambda") + + def moto_network_name(): return os.environ.get("MOTO_DOCKER_NETWORK_NAME")