Add dev config flag for fixing lambda invoke on macOS in host mode by joe4dev · Pull Request #7367 · localstack/localstack · GitHub
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions localstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from localstack.aws.api.lambda_ import PackageType, Runtime
from localstack.services.awslambda import hooks as lambda_hooks
from localstack.services.awslambda.invocation.executor_endpoint import (
INVOCATION_PORT,
ExecutorEndpoint,
ServiceEndpoint,
)
Expand All @@ -25,10 +26,12 @@
from localstack.services.awslambda.packages import awslambda_runtime_package
from localstack.utils.container_utils.container_client import (
ContainerConfiguration,
PortMappings,
VolumeBind,
VolumeMappings,
)
from localstack.utils.docker_utils import DOCKER_CLIENT as CONTAINER_CLIENT
from localstack.utils.net import get_free_tcp_port
from localstack.utils.strings import truncate

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -249,7 +252,11 @@ def start(self, env_vars: dict[str, str]) -> None:

if not container_config.image_name:
container_config.image_name = self.get_image()

if config.LAMBDA_DEV_PORT_EXPOSE:
self.executor_endpoint.container_port = get_free_tcp_port()
if container_config.ports is None:
container_config.ports = PortMappings()
container_config.ports.add(self.executor_endpoint.container_port, INVOCATION_PORT)
CONTAINER_CLIENT.create_container_from_config(container_config)
if (
not config.LAMBDA_PREBUILD_IMAGES
Expand All @@ -267,6 +274,8 @@ def start(self, env_vars: dict[str, str]) -> None:
self.ip = CONTAINER_CLIENT.get_container_ipv4_for_network(
container_name_or_id=self.id, container_network=network
)
if config.LAMBDA_DEV_PORT_EXPOSE:
self.ip = "127.0.0.1"
self.executor_endpoint.container_address = self.ip

def stop(self) -> None:
Expand Down