8000 additional debugging for network connection failure (#8602) · codeperl/localstack@2408239 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2408239

Browse files
authored
additional debugging for network connection failure (localstack#8602)
1 parent b411df5 commit 2408239

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

localstack/services/awslambda/invocation/lambda_models.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from abc import ABCMeta, abstractmethod
88
from datetime import datetime
99
from pathlib import Path
10-
from typing import IO, TYPE_CHECKING, Dict, Optional, TypedDict
10+
from typing import IO, Dict, Optional, TypedDict
1111

1212
from botocore.exceptions import ClientError
1313

@@ -31,14 +31,11 @@
3131
StateReasonCode,
3232
TracingMode,
3333
)
34+
from localstack.aws.connect import connect_to
3435
from localstack.services.awslambda.api_utils import qualified_lambda_arn, unqualified_lambda_arn
3536
from localstack.utils.archives import unzip
36-
from localstack.utils.aws import aws_stack
3737
from localstack.utils.strings import long_uid
3838

39-
if TYPE_CHECKING:
40-
from mypy_boto3_s3 import S3Client
41-
4239
LOG = logging.getLogger(__name__)
4340

4441
# To add support for a new runtime, just add it here with the accompanying image postfix
@@ -168,7 +165,7 @@ def _download_archive_to_file(self, target_file: IO) -> None:
168165
169166
:param target_file: File the code archive should be downloaded into (IO object)
170167
"""
171-
s3_client: "S3Client" = aws_stack.connect_to_service("s3", region_name="us-east-1")
168+
s3_client = connect_to(region_name="us-east-1").s3
172169
extra_args = {"VersionId": self.s3_object_version} if self.s3_object_version else {}
173170
s3_client.download_fileobj(
174171
Bucket=self.s3_bucket, Key=self.s3_key, Fileobj=target_file, ExtraArgs=extra_args
@@ -179,9 +176,7 @@ def generate_presigned_url(self, endpoint_url: str | None = None) -> str:
179176
"""
180177
Generates a presigned url pointing to the code archive
181178
"""
182-
s3_client: "S3Client" = aws_stack.connect_to_service(
183-
"s3", region_name="us-east-1", endpoint_url=endpoint_url
184-
)
179+
s3_client = connect_to(region_name="us-east-1", endpoint_url=endpoint_url).s3
185180
params = {"Bucket": self.s3_bucket, "Key": self.s3_key}
186181
if self.s3_object_version:
187182
params["VersionId"] = self.s3_object_version
@@ -239,7 +234,7 @@ def destroy(self) -> None:
239234
"""
240235
LOG.debug("Final code destruction for %s", self.id)
241236
self.destroy_cached()
242-
s3_client: "S3Client" = aws_stack.connect_to_service("s3", region_name="us-east-1")
237+
s3_client = connect_to(region_name="us-east-1").s3
243238
kwargs = {"VersionId": self.s3_object_version} if self.s3_object_version else {}
244239
try:
245240
s3_client.delete_object(Bucket=self.s3_bucket, Key=self.s3_key, **kwargs)

localstack/utils/container_utils/container_client.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,11 @@ class ContainerConfiguration:
413413
command: Optional[List[str]] = None
414414
env_vars: Dict[str, str] = dataclasses.field(default_factory=dict)
415415

416-
privileged: Optional[bool] = None
417-
remove: Optional[bool] = None
418-
interactive: Optional[bool] = None
419-
tty: Optional[bool] = None
420-
detach: Optional[bool] = None
416+
privileged: bool = False
417+
remove: bool = False
418+
interactive: bool = False
419+
tty: bool = False
420+
detach: bool = False
421421

422422
stdin: Optional[str] = None
423423
user: Optional[str] = None
@@ -492,6 +492,14 @@ def get_container_ipv4_for_network(
492492
network_attrs = self.inspect_network(container_network)
493493
containers = network_attrs.get("Containers") or {}
494494
if container_id not in containers:
495+
LOG.debug("Network attributes: %s", network_attrs)
496+
try:
497+
inspection = self.inspect_container(container_name_or_id=container_name_or_id)
498+
LOG.debug("Container %s Attributes: %s", container_name_or_id, inspection)
499+
logs = self.get_container_logs(container_name_or_id=container_name_or_id)
500+
LOG.debug("Container %s Logs: %s", container_name_or_id, logs)
501+
except ContainerException as e:
502+
LOG.debu 477C g("Cannot inspect container %s: %s", container_name_or_id, e)
495503
raise ContainerException(
496504
"Container %s is not connected to target network %s",
497505
container_name_or_id,

0 commit comments

Comments
 (0)
0