From 787ee6fec97ad9ee2e96060d1cdc12a5134168ae Mon Sep 17 00:00:00 2001 From: Daniel Fangl Date: Mon, 3 Jul 2023 12:16:00 +0200 Subject: [PATCH 1/3] create additional debug logs if container is not connected to network after start, add proper defaults in container configuration --- .../utils/container_utils/container_client.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/localstack/utils/container_utils/container_client.py b/localstack/utils/container_utils/container_client.py index 2efa61968d185..e59e4b8446e36 100644 --- a/localstack/utils/container_utils/container_client.py +++ b/localstack/utils/container_utils/container_client.py @@ -413,11 +413,11 @@ class ContainerConfiguration: command: Optional[List[str]] = None env_vars: Dict[str, str] = dataclasses.field(default_factory=dict) - privileged: Optional[bool] = None - remove: Optional[bool] = None - interactive: Optional[bool] = None - tty: Optional[bool] = None - detach: Optional[bool] = None + privileged: bool = False + remove: bool = False + interactive: bool = False + tty: bool = False + detach: bool = False stdin: Optional[str] = None user: Optional[str] = None @@ -492,6 +492,14 @@ def get_container_ipv4_for_network( network_attrs = self.inspect_network(container_network) containers = network_attrs.get("Containers") or {} if container_id not in containers: + LOG.debug("Network attributes: %s", network_attrs) + try: + inspection = self.inspect_container(container_name_or_id=container_name_or_id) + LOG.debug("Container %s Attributes: %s", container_name_or_id, inspection) + logs = self.get_container_logs(container_name_or_id=container_name_or_id) + LOG.debug("Container %s Logs: %s", container_name_or_id, logs) + except ContainerException as e: + LOG.debug("Cannot inspect container %s: %s", container_name_or_id, e) raise ContainerException( "Container %s is not connected to target network %s", container_name_or_id, From 000a3745dcccb8c11bd5aa99a862e31860538621 Mon Sep 17 00:00:00 2001 From: Daniel Fangl Date: Mon, 3 Jul 2023 13:16:38 +0200 Subject: [PATCH 2/3] client migration --- .../awslambda/invocation/lambda_models.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/localstack/services/awslambda/invocation/lambda_models.py b/localstack/services/awslambda/invocation/lambda_models.py index 3b9c5c14ed899..a486981644825 100644 --- a/localstack/services/awslambda/invocation/lambda_models.py +++ b/localstack/services/awslambda/invocation/lambda_models.py @@ -7,7 +7,7 @@ from abc import ABCMeta, abstractmethod from datetime import datetime from pathlib import Path -from typing import IO, TYPE_CHECKING, Dict, Optional, TypedDict +from typing import IO, Dict, Optional, TypedDict from botocore.exceptions import ClientError @@ -31,14 +31,11 @@ StateReasonCode, TracingMode, ) +from localstack.aws.connect import connect_to from localstack.services.awslambda.api_utils import qualified_lambda_arn, unqualified_lambda_arn from localstack.utils.archives import unzip -from localstack.utils.aws import aws_stack from localstack.utils.strings import long_uid -if TYPE_CHECKING: - from mypy_boto3_s3 import S3Client - LOG = logging.getLogger(__name__) # 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: :param target_file: File the code archive should be downloaded into (IO object) """ - s3_client: "S3Client" = aws_stack.connect_to_service("s3", region_name="us-east-1") + s3_client = connect_to(region_name="us-east-1").s3 extra_args = {"VersionId": self.s3_object_version} if self.s3_object_version else {} s3_client.download_fileobj( 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: """ Generates a presigned url pointing to the code archive """ - s3_client: "S3Client" = aws_stack.connect_to_service( - "s3", region_name="us-east-1", endpoint_url=endpoint_url - ) + s3_client = connect_to(region_name="us-east-1", endpoint_url=endpoint_url) params = {"Bucket": self.s3_bucket, "Key": self.s3_key} if self.s3_object_version: params["VersionId"] = self.s3_object_version @@ -239,7 +234,7 @@ def destroy(self) -> None: """ LOG.debug("Final code destruction for %s", self.id) self.destroy_cached() - s3_client: "S3Client" = aws_stack.connect_to_service("s3", region_name="us-east-1") + s3_client = connect_to(region_name="us-east-1").s3 kwargs = {"VersionId": self.s3_object_version} if self.s3_object_version else {} try: s3_client.delete_object(Bucket=self.s3_bucket, Key=self.s3_key, **kwargs) From 17dc21c5f6f2ea2999bbdfe5cd3eee70a3046f27 Mon Sep 17 00:00:00 2001 From: Daniel Fangl Date: Mon, 3 Jul 2023 15:22:51 +0200 Subject: [PATCH 3/3] fix missing s3 discriminator --- localstack/services/awslambda/invocation/lambda_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localstack/services/awslambda/invocation/lambda_models.py b/localstack/services/awslambda/invocation/lambda_models.py index a486981644825..beca15d880152 100644 --- a/localstack/services/awslambda/invocation/lambda_models.py +++ b/localstack/services/awslambda/invocation/lambda_models.py @@ -176,7 +176,7 @@ def generate_presigned_url(self, endpoint_url: str | None = None) -> str: """ Generates a presigned url pointing to the code archive """ - s3_client = connect_to(region_name="us-east-1", endpoint_url=endpoint_url) + s3_client = connect_to(region_name="us-east-1", endpoint_url=endpoint_url).s3 params = {"Bucket": self.s3_bucket, "Key": self.s3_key} if self.s3_object_version: params["VersionId"] = self.s3_object_version