add host.docker.internal for inter-AWS communication mocking on linux (#4408)

This commit is contained in:
Todd Morse 2021-10-13 17:35:38 -04:00 committed by GitHub
parent e8cd02617d
commit f451153c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ from collections import defaultdict
import copy
import datetime
from gzip import GzipFile
from sys import platform
import docker
import docker.errors
@ -577,6 +578,13 @@ class LambdaFunction(CloudFormationModel, DockerModel):
if settings.TEST_SERVER_MODE
else {}
)
# add host.docker.internal host on linux to emulate Mac + Windows behavior
# for communication with other mock AWS services running on localhost
if platform == "linux" or platform == "linux2":
run_kwargs["extra_hosts"] = {
"host.docker.internal": "host-gateway"
}
image_ref = "lambci/lambda:{}".format(self.run_time)
self.docker_client.images.pull(":".join(parse_image_ref(image_ref)))
container = self.docker_client.containers.run(