7
7
from abc import ABCMeta , abstractmethod
8
8
from datetime import datetime
9
9
from pathlib import Path
10
- from typing import IO , TYPE_CHECKING , Dict , Optional , TypedDict
10
+ from typing import IO , Dict , Optional , TypedDict
11
11
12
12
from botocore .exceptions import ClientError
13
13
31
31
StateReasonCode ,
32
32
TracingMode ,
33
33
)
34
+ from localstack .aws .connect import connect_to
34
35
from localstack .services .awslambda .api_utils import qualified_lambda_arn , unqualified_lambda_arn
35
36
from localstack .utils .archives import unzip
36
- from localstack .utils .aws import aws_stack
37
37
from localstack .utils .strings import long_uid
38
38
39
- if TYPE_CHECKING :
40
- from mypy_boto3_s3 import S3Client
41
-
42
39
LOG = logging .getLogger (__name__ )
43
40
44
41
# 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:
168
165
169
166
:param target_file: File the code archive should be downloaded into (IO object)
170
167
"""
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
172
169
extra_args = {"VersionId" : self .s3_object_version } if self .s3_object_version else {}
173
170
s3_client .download_fileobj (
174
171
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:
179
176
"""
180
177
Generates a presigned url pointing to the code archive
181
178
"""
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
185
180
params = {"Bucket" : self .s3_bucket , "Key" : self .s3_key }
186
181
if self .s3_object_version :
187
182
params ["VersionId" ] = self .s3_object_version
@@ -239,7 +234,7 @@ def destroy(self) -> None:
239
234
"""
240
235
LOG .debug ("Final code destruction for %s" , self .id )
241
236
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
243
238
kwargs = {"VersionId" : self .s3_object_version } if self .s3_object_version else {}
244
239
try :
245
240
s3_client .delete_object (Bucket = self .s3_bucket , Key = self .s3_key , ** kwargs )
0 commit comments