Skip to content

Commit b6027e9

Browse files
authored
Merge branch 'aws:develop' into expanded-parameter-overrides
2 parents 27f03ca + 80b67a4 commit b6027e9

File tree

126 files changed

+593
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+593
-546
lines changed

samcli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
SAM CLI version
33
"""
44

5-
__version__ = "1.132.0"
5+
__version__ = "1.133.0"

samcli/lib/build/app_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
AWS_SERVERLESS_LAYERVERSION,
6262
)
6363
from samcli.lib.utils.stream_writer import StreamWriter
64+
from samcli.local.docker.container import ContainerContext
6465
from samcli.local.docker.lambda_build_container import LambdaBuildContainer
6566
from samcli.local.docker.manager import ContainerManager, DockerImagePullFailedException
6667
from samcli.local.docker.utils import get_docker_platform, is_docker_reachable
@@ -968,7 +969,7 @@ def _build_function_on_container(
968969

969970
try:
970971
try:
971-
self._container_manager.run(container)
972+
self._container_manager.run(container, context=ContainerContext.BUILD)
972973
except docker.errors.APIError as ex:
973974
if "executable file not found in $PATH" in str(ex):
974975
raise UnsupportedBuilderLibraryVersionError(

samcli/local/docker/container.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import tempfile
1414
import threading
1515
import time
16+
from enum import Enum
1617
from typing import Dict, Iterator, Optional, Tuple, Union
1718

1819
import docker
@@ -59,6 +60,11 @@ class ContainerConnectionTimeoutException(Exception):
5960
"""
6061

6162

63+
class ContainerContext(Enum):
64+
BUILD = "build"
65+
INVOKE = "invoke"
66+
67+
6268
class Container:
6369
"""
6470
Represents an instance of a Docker container with a specific configuration. The container is not actually created
@@ -157,11 +163,14 @@ def __init__(
157163
except NoFreePortsError as ex:
158164
raise ContainerNotStartableException(str(ex)) from ex
159165

160-
def create(self):
166+
def create(self, context):
161167
"""
162168
Calls Docker API to creates the Docker container instance. Creating the container does *not* run the container.
163169
Use ``start`` method to run the container
164170
171+
context: samcli.local.docker.container.ContainerContext
172+
Context for the container management to run (build, invoke)
173+
165174
:return string: ID of the created container
166175
:raise RuntimeError: If this method is called after a container already has been created
167176
"""
@@ -174,6 +183,7 @@ def create(self):
174183
if self._host_dir:
175184
mount_mode = "rw,delegated" if self._mount_with_write else "ro,delegated"
176185
LOG.info("Mounting %s as %s:%s, inside runtime container", self._host_dir, self._working_dir, mount_mode)
186+
mapped_symlinks = self._create_mapped_symlink_files() if self._resolve_symlinks(context) else {}
177187

178188
_volumes = {
179189
self._host_dir: {
@@ -182,7 +192,7 @@ def create(self):
182192
"bind": self._working_dir,
183193
"mode": mount_mode,
184194
},
185-
**self._create_mapped_symlink_files(),
195+
**mapped_symlinks,
186196
}
187197

188198
kwargs = {
@@ -648,3 +658,18 @@ def is_running(self):
648658
return real_container.status == "running"
649659
except docker.errors.NotFound:
650660
return False
661+
662+
def _resolve_symlinks(self, context) -> bool:
663+
"""_summary_
664+
665+
Parameters
666+
----------
667+
context : sacli.local.docker.container.ContainerContext
668+
Context for the container management to run. (build, invoke)
669+
670+
Returns
671+
-------
672+
bool
673+
True, if given these parameters it should resolve symlinks or not
674+
"""
675+
return bool(context != ContainerContext.BUILD)

samcli/local/docker/manager.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from samcli.lib.constants import DOCKER_MIN_API_VERSION
1313
from samcli.lib.utils.stream_writer import StreamWriter
1414
from samcli.local.docker import utils
15-
from samcli.local.docker.container import Container
15+
from samcli.local.docker.container import Container, ContainerContext
1616
from samcli.local.docker.lambda_image import LambdaImage
1717

1818
LOG = logging.getLogger(__name__)
@@ -55,14 +55,16 @@ def is_docker_reachable(self):
5555
"""
5656
return utils.is_docker_reachable(self.docker_client)
5757

58-
def create(self, container):
58+
def create(self, container, context):
5959
"""
6060
Create a container based on the given configuration.
6161
6262
Parameters
6363
----------
6464
container samcli.local.docker.container.Container:
6565
Container to be created
66+
context: samcli.local.docker.container.ContainerContext
67+
Context for the container management to run. (build, invoke)
6668
6769
Raises
6870
------
@@ -93,9 +95,9 @@ def create(self, container):
9395
LOG.info("Failed to download a new %s image. Invoking with the already downloaded image.", image_name)
9496

9597
container.network_id = self.docker_network_id
96-
container.create()
98+
container.create(context)
9799

98-
def run(self, container, input_data=None):
100+
def run(self, container, context: ContainerContext, input_data=None):
99101
"""
100102
Run a Docker container based on the given configuration.
101103
If the container is not created, it will call Create method to create.
@@ -104,6 +106,8 @@ def run(self, container, input_data=None):
104106
----------
105107
container: samcli.local.docker.container.Container
106108
Container to create and run
109+
context: samcli.local.docker.container.ContainerContext
110+
Context for the container management to run. (build, invoke)
107111
input_data: str, optional
108112
Input data sent to the container through container's stdin.
109113
@@ -113,8 +117,7 @@ def run(self, container, input_data=None):
113117
If the Docker image was not available in the server
114118
"""
115119
if not container.is_created():
116-
self.create(container)
117-
120+
self.create(container, context)
118121
container.start(input_data=input_data)
119122

120123
def stop(self, container: Container) -> None:

samcli/local/lambdafn/runtime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from samcli.lib.telemetry.metric import capture_parameter
1515
from samcli.lib.utils.file_observer import LambdaFunctionObserver
1616
from samcli.lib.utils.packagetype import ZIP
17-
from samcli.local.docker.container import Container
17+
from samcli.local.docker.container import Container, ContainerContext
1818
from samcli.local.docker.container_analyzer import ContainerAnalyzer
1919
from samcli.local.docker.exceptions import ContainerFailureError, DockerContainerCreationFailedException
2020
from samcli.local.docker.lambda_container import LambdaContainer
@@ -113,7 +113,7 @@ def create(
113113
)
114114
try:
115115
# create the container.
116-
self._container_manager.create(container)
116+
self._container_manager.create(container, ContainerContext.INVOKE)
117117
return container
118118

119119
except DockerContainerCreationFailedException:
@@ -174,7 +174,7 @@ def run(
174174

175175
try:
176176
# start the container.
177-
self._container_manager.run(container)
177+
self._container_manager.run(container, ContainerContext.INVOKE)
178178
return container
179179

180180
except KeyboardInterrupt:

tests/integration/deploy/test_deploy_command.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class TestDeploy(DeployIntegBase):
2626
def setUpClass(cls):
2727
cls.docker_client = docker.from_env()
2828
cls.local_images = [
29-
("public.ecr.aws/sam/emulation-python3.8", "latest"),
29+
("public.ecr.aws/sam/emulation-python3.9", "latest"),
3030
]
3131
# setup some images locally by pulling them.
3232
for repo, tag in cls.local_images:
3333
cls.docker_client.api.pull(repository=repo, tag=tag)
34-
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.8", tag="latest")
35-
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.8-2", tag="latest")
34+
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.9", tag="latest")
35+
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.9-2", tag="latest")
3636
cls.docker_client.api.tag(f"{repo}:{tag}", "colorsrandomfunctionf61b9209", tag="latest")
3737

3838
# setup signing profile arn & name

tests/integration/local/invoke/test_invoke_terraform_applications.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def setUpClass(cls):
210210
bytes('resource "aws_lambda_function" "this" {' + os.linesep, "utf-8"),
211211
bytes(" filename = var.source_code" + os.linesep, "utf-8"),
212212
bytes(' handler = "app.lambda_handler"' + os.linesep, "utf-8"),
213-
bytes(' runtime = "python3.8"' + os.linesep, "utf-8"),
213+
bytes(' runtime = "python3.9"' + os.linesep, "utf-8"),
214214
bytes(" function_name = var.function_name" + os.linesep, "utf-8"),
215215
bytes(" role = aws_iam_role.iam_for_lambda.arn" + os.linesep, "utf-8"),
216216
bytes(f' layers = ["{_4th_layer_arn}"]' + os.linesep, "utf-8"),

tests/integration/local/start_api/test_start_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,19 +1549,19 @@ def assert_cors(self, response):
15491549
self.assertEqual(response.headers.get("Access-Control-Allow-Credentials"), "true")
15501550
self.assertEqual(response.headers.get("Access-Control-Max-Age"), "510")
15511551

1552+
@parameterized.expand(["https://abc", None])
15521553
@pytest.mark.flaky(reruns=3)
15531554
@pytest.mark.timeout(timeout=600, method="thread")
1554-
@parameterized.expand(["https://abc", None])
15551555
def test_cors_swagger_options(self, origin):
15561556
"""
15571557
This tests that the Cors headers are added to OPTIONS responses
15581558
"""
15591559
response = requests.options(self.url + "/echobase64eventbody", **_create_request_params(origin))
15601560
self.assert_cors(response)
15611561

1562+
@parameterized.expand(["https://abc", None])
15621563
@pytest.mark.flaky(reruns=3)
15631564
@pytest.mark.timeout(timeout=600, method="thread")
1564-
@parameterized.expand(["https://abc", None])
15651565
def test_cors_swagger_get(self, origin):
15661566
"""
15671567
This tests that the Cors headers are added to _other_ method responses
@@ -1685,9 +1685,9 @@ class TestServiceCorsGlobalRequests(StartApiIntegBaseClass):
16851685
def setUp(self):
16861686
self.url = "http://127.0.0.1:{}".format(self.port)
16871687

1688+
@parameterized.expand(["https://abc", None])
16881689
@pytest.mark.flaky(reruns=3)
16891690
@pytest.mark.timeout(timeout=600, method="thread")
1690-
@parameterized.expand(["https://abc", None])
16911691
def test_cors_global(self, origin):
16921692
"""
16931693
This tests that the Cors headers are added to OPTIONS response when the global property is set

tests/integration/local/start_lambda/test_start_lambda_terraform_applications.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def setUpClass(cls):
213213
bytes('resource "aws_lambda_function" "this" {' + os.linesep, "utf-8"),
214214
bytes(" filename = var.source_code" + os.linesep, "utf-8"),
215215
bytes(' handler = "app.lambda_handler"' + os.linesep, "utf-8"),
216-
bytes(' runtime = "python3.8"' + os.linesep, "utf-8"),
216+
bytes(' runtime = "python3.9"' + os.linesep, "utf-8"),
217217
bytes(" function_name = var.function_name" + os.linesep, "utf-8"),
218218
bytes(" role = aws_iam_role.iam_for_lambda.arn" + os.linesep, "utf-8"),
219219
bytes(f' layers = ["{_4th_layer_arn}"]' + os.linesep, "utf-8"),

tests/integration/package/test_package_command_image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class TestPackageImage(PackageIntegBase):
2626
def setUpClass(cls):
2727
cls.docker_client = docker.from_env()
2828
cls.local_images = [
29-
("public.ecr.aws/sam/emulation-python3.8", "latest"),
29+
("public.ecr.aws/sam/emulation-python3.9", "latest"),
3030
]
3131
# setup some images locally by pulling them.
3232
for repo, tag in cls.local_images:
3333
cls.docker_client.api.pull(repository=repo, tag=tag)
34-
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.8", tag="latest")
35-
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.8-2", tag="latest")
34+
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.9", tag="latest")
35+
cls.docker_client.api.tag(f"{repo}:{tag}", "emulation-python3.9-2", tag="latest")
3636
cls.docker_client.api.tag(f"{repo}:{tag}", "colorsrandomfunctionf61b9209", tag="latest")
3737

3838
super(TestPackageImage, cls).setUpClass()
@@ -264,8 +264,8 @@ def test_package_with_deep_nested_template_image(self):
264264

265265
# verify all function images are pushed
266266
images = [
267-
("emulation-python3.8", "latest"),
268-
("emulation-python3.8-2", "latest"),
267+
("emulation-python3.9", "latest"),
268+
("emulation-python3.9-2", "latest"),
269269
]
270270
for image, tag in images:
271271
# check string like this:

0 commit comments

Comments
 (0)