Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/pip/requirements/develop/setup…
Browse files Browse the repository at this point in the history
…tools-74.0.0
  • Loading branch information
jysheng123 authored Sep 6, 2024
2 parents 2db4af9 + 7d0800a commit 566285b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 15 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ requests~=2.32.3
aws_lambda_builders==1.50.0
tomlkit==0.13.2
watchdog==4.0.2
rich~=13.7.1
rich~=13.8.0
pyopenssl~=24.2.1
# Pin to <4.18 to until SAM-T no longer uses RefResolver
jsonschema<4.24
Expand Down
6 changes: 3 additions & 3 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,9 @@ requests==2.32.3 \
# aws-sam-cli (setup.py)
# cookiecutter
# docker
rich==13.7.1 \
--hash=sha256:4edbae314f59eb482f54e9e30bf00d33350aaa94f4bfcd4e9e3110e64d0d7222 \
--hash=sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432
rich==13.8.0 \
--hash=sha256:2e85306a063b9492dffc86278197a60cbece75bcb766022f3436f567cae11bdc \
--hash=sha256:a5ac1f1cd448ade0d59cc3356f7db7a7ccda2c8cbae9c7a90c28ff463d3e91f4
# via
# aws-sam-cli (setup.py)
# cookiecutter
Expand Down
12 changes: 6 additions & 6 deletions requirements/reproducible-mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ requests==2.32.3 \
# aws-sam-cli (setup.py)
# cookiecutter
# docker
rich==13.7.1 \
--hash=sha256:4edbae314f59eb482f54e9e30bf00d33350aaa94f4bfcd4e9e3110e64d0d7222 \
--hash=sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432
rich==13.8.0 \
--hash=sha256:2e85306a063b9492dffc86278197a60cbece75bcb766022f3436f567cae11bdc \
--hash=sha256:a5ac1f1cd448ade0d59cc3356f7db7a7ccda2c8cbae9c7a90c28ff463d3e91f4
# via
# aws-sam-cli (setup.py)
# cookiecutter
Expand Down Expand Up @@ -1060,9 +1060,9 @@ wheel==0.44.0 \
--hash=sha256:2376a90c98cc337d18623527a97c31797bd02bad0033d41547043a1cbfbe448f \
--hash=sha256:a29c3f2817e95ab89aa4660681ad547c0e9547f20e75b0562fe7723c9a2a9d49
# via aws-lambda-builders
zipp==3.20.0 \
--hash=sha256:0145e43d89664cfe1a2e533adc75adafed82fe2da404b4bbb6b026c0157bdb31 \
--hash=sha256:58da6168be89f0be59beb194da1250516fdaa062ccebd30127ac65d30045e10d
zipp==3.20.1 \
--hash=sha256:9960cd8967c8f85a56f920d5d507274e74f9ff813a0ab8889a5b5be2daf44064 \
--hash=sha256:c22b14cc4763c5a5b04134207736c107db42e9d3ef2d9779d465f5f1bcba572b
# via
# importlib-metadata
# importlib-resources
Expand Down
6 changes: 3 additions & 3 deletions requirements/reproducible-win.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,9 @@ requests==2.32.3 \
# aws-sam-cli (setup.py)
# cookiecutter
# docker
rich==13.7.1 \
--hash=sha256:4edbae314f59eb482f54e9e30bf00d33350aaa94f4bfcd4e9e3110e64d0d7222 \
--hash=sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432
rich==13.8.0 \
--hash=sha256:2e85306a063b9492dffc86278197a60cbece75bcb766022f3436f567cae11bdc \
--hash=sha256:a5ac1f1cd448ade0d59cc3356f7db7a7ccda2c8cbae9c7a90c28ff463d3e91f4
# via
# aws-sam-cli (setup.py)
# cookiecutter
Expand Down
3 changes: 2 additions & 1 deletion samcli/local/layers/layer_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import logging
import uuid
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -106,7 +107,7 @@ def download(self, layer: LayerVersion, force=False) -> LayerVersion:
LOG.info("%s is already cached. Skipping download", layer.arn)
return layer

layer_zip_path = layer.codeuri + ".zip"
layer_zip_path = f"{layer.codeuri}_{uuid.uuid4().hex}.zip"
layer_zip_uri = self._fetch_layer_uri(layer)
unzip_from_uri(
layer_zip_uri,
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/local/start_api/test_start_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,20 @@ def test_can_invoke_lambda_layer_successfully(self):
self.assertEqual(response.content.decode("utf-8"), '"Layer1"')


class TestWarmContainersMultipleRemoteLayersInvoke(WarmContainersWithRemoteLayersBase):
template_path = "/testdata/start_api/template-warm-containers-multi-layers.yaml"
container_mode = ContainersInitializationMode.EAGER.value
mode_env_variable = str(uuid.uuid4())
parameter_overrides = {"ModeEnvVariable": mode_env_variable}

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=600, method="thread")
def test_can_invoke_lambda_layer_successfully(self):
response = requests.get(self.url + "/", timeout=300)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode("utf-8"), '"Layer1"')


class TestDisableAuthorizer(StartApiIntegBaseClass):
# integration test for scenario: 'sam local start-api --disable-authorizer'
template_path = "/testdata/start_api/lambda_authorizers/serverless-api-props.yaml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
ModeEnvVariable:
Type: String
LayerArn:
Default: arn:aws:lambda:us-west-2:111111111111:layer:layer:1
Type: String

Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
CacheClusterEnabled: true
CacheClusterSize: '0.5'
MethodSettings:
- ResourcePath: /
HttpMethod: GET
CachingEnabled: true
CacheTtlInSeconds: 300
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Handler: main-layers.custom_layer_handler
Runtime: python3.9
FunctionName: customname
CodeUri: .
Timeout: 600
Environment:
Variables:
MODE: !Ref ModeEnvVariable
Layers:
# Test remote layers with warm containers.
- Ref: LayerArn
Events:
ApiEvent:
Type: Api
Properties:
Path: /
Method: get
RestApiId:
Ref: ApiGatewayApi
HelloWorldFunction2:
Type: AWS::Serverless::Function
Properties:
Handler: main-layers.custom_layer_handler
Runtime: python3.9
FunctionName: customname
CodeUri: .
Timeout: 600
Environment:
Variables:
MODE: !Ref ModeEnvVariable
Layers:
# Test remote layers with warm containers.
- Ref: LayerArn
Events:
ApiEvent:
Type: Api
Properties:
Path: /
Method: get
RestApiId:
Ref: ApiGatewayApi
HelloWorldFunction3:
Type: AWS::Serverless::Function
Properties:
Handler: main-layers.custom_layer_handler
Runtime: python3.9
FunctionName: customname
CodeUri: .
Timeout: 600
Environment:
Variables:
MODE: !Ref ModeEnvVariable
Layers:
# Test remote layers with warm containers.
- Ref: LayerArn
Events:
ApiEvent:
Type: Api
Properties:
Path: /
Method: get
RestApiId:
Ref: ApiGatewayApi
6 changes: 5 additions & 1 deletion tests/unit/local/layers/test_download_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def test_download_layer_that_was_template_defined(self, create_cache_patch, reso
def test_download_layer(
self, is_layer_cached_patch, create_cache_patch, fetch_layer_uri_patch, unzip_from_uri_patch
):
class AnyStringWith(str):
def __eq__(self, other):
return self in other

is_layer_cached_patch.return_value = False

download_layers = LayerDownloader("/home", ".", Mock())
Expand All @@ -118,7 +122,7 @@ def test_download_layer(
fetch_layer_uri_patch.assert_called_once_with(layer_mock)
unzip_from_uri_patch.assert_called_once_with(
"layer/uri",
str(Path("/home/layer1.zip").resolve()),
AnyStringWith(str(Path("/home/layer1_"))),
unzip_output_dir=str(Path("/home/layer1").resolve()),
progressbar_label="Downloading arn:layer:layer1",
)
Expand Down

0 comments on commit 566285b

Please sign in to comment.