Skip to content

Commit

Permalink
Merge from aws/aws-sam-cli/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sam-cli-bot authored Jun 13, 2024
2 parents 23bbacd + f175f35 commit 16d748b
Show file tree
Hide file tree
Showing 27 changed files with 844 additions and 623 deletions.
8 changes: 4 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ aws-sam-translator==1.89.0
#docker minor version updates can include breaking changes. Auto update micro version only.
docker~=7.1.0
dateparser~=1.2
requests~=2.32.2
requests~=2.32.3
aws_lambda_builders==1.50.0
tomlkit==0.12.5
watchdog==4.0.0
watchdog==4.0.1
rich~=13.7.1
pyopenssl~=24.1.0
# Pin to <4.18 to until SAM-T no longer uses RefResolver
Expand All @@ -28,7 +28,7 @@ regex!=2021.10.8
tzlocal==5.2

#Adding cfn-lint dependency for SAM validate
cfn-lint~=0.87.3
cfn-lint~=0.87.7

# Type checking boto3 objects
boto3-stubs[apigateway,cloudformation,ecr,iam,lambda,s3,schemas,secretsmanager,signer,stepfunctions,sts,xray,sqs,kinesis]==1.34.111
boto3-stubs[apigateway,cloudformation,ecr,iam,lambda,s3,schemas,secretsmanager,signer,stepfunctions,sts,xray,sqs,kinesis]==1.34.123
12 changes: 7 additions & 5 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r pre-dev.txt

coverage==7.5.1
coverage==7.5.3
pytest-cov==5.0.0


Expand All @@ -12,15 +12,17 @@ types-pywin32==306.0.0.20240408
types-PyYAML==6.0.12.20240311
types-chevron==0.14.2.20240310
types-psutil==5.9.5.20240516
types-setuptools==69.5.0.20240513
types-setuptools==70.0.0.20240524
types-Pygments==2.18.0.20240506
types-colorama==0.4.15.20240311
types-dateparser==1.2.0.20240420
types-docutils==0.21.0.20240423
types-jsonschema==4.22.0.20240501
types-jsonschema==4.22.0.20240610
types-pyOpenSSL==24.1.0.20240425
# as of types-requests>=2.31.0.7, this now requires `urllib3>2`, pin we are able to upgrade
types-requests==2.31.0.6
# lucashuy: pin `types-request` based on the Python version since newer versions of
# the types require a newer version of requests, which is only installed in newer versions of Python
types-requests==2.31.0.6; python_version<"3.10"
types-requests==2.32.0.20240602; python_version>="3.10"
types-urllib3==1.26.25.14

# Test requirements
Expand Down
2 changes: 1 addition & 1 deletion requirements/pre-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruff==0.4.5
ruff==0.4.8
4 changes: 2 additions & 2 deletions requirements/pyinstaller-build.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Executable binary builder requirements
setuptools==69.5.1
pyinstaller==6.7.0
setuptools==70.0.0
pyinstaller==6.8.0
385 changes: 194 additions & 191 deletions requirements/reproducible-linux.txt

Large diffs are not rendered by default.

391 changes: 197 additions & 194 deletions requirements/reproducible-mac.txt

Large diffs are not rendered by default.

385 changes: 194 additions & 191 deletions requirements/reproducible-win.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = "1.118.0"
__version__ = "1.119.0"
2 changes: 1 addition & 1 deletion samcli/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __init__(self, multiple_values_per_key=False):

_pattern = r"{tag}={tag}".format(tag=_generate_match_regex(match_pattern=TAG_REGEX, delim=" "))

name = "list"
name = "string,list"

def convert(self, value, param, ctx):
result = {}
Expand Down
3 changes: 2 additions & 1 deletion samcli/commands/_utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,9 @@ def resolve_s3_click_option(guided):
)
)
return click.option(
"--resolve-s3",
"--resolve-s3/--no-resolve-s3",
required=False,
default=False,
is_flag=True,
callback=callback,
help="Automatically resolve AWS S3 bucket for non-guided deployments. "
Expand Down
23 changes: 23 additions & 0 deletions samcli/commands/local/cli_common/invoke_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, TextIO, Tuple, Type, cast

from botocore.exceptions import ClientError, NoCredentialsError, TokenRetrievalError

from samcli.commands._utils.template import TemplateFailedParsingException, TemplateNotFoundException
from samcli.commands.exceptions import ContainersInitializationException
from samcli.commands.local.cli_common.user_exceptions import DebugContextException, InvokeContextException
Expand All @@ -20,6 +22,7 @@
from samcli.lib.providers.sam_stack_provider import SamLocalStackProvider
from samcli.lib.utils import osutils
from samcli.lib.utils.async_utils import AsyncContext
from samcli.lib.utils.boto_utils import get_boto_client_provider_with_config
from samcli.lib.utils.packagetype import ZIP
from samcli.lib.utils.stream_writer import StreamWriter
from samcli.local.docker.exceptions import PortAlreadyInUse
Expand Down Expand Up @@ -178,6 +181,7 @@ def __init__(
self._aws_region = aws_region
self._aws_profile = aws_profile
self._shutdown = shutdown
self._add_account_id_to_global()

self._container_host = container_host
self._container_host_interface = container_host_interface
Expand Down Expand Up @@ -345,6 +349,25 @@ def _clean_running_containers_and_related_resources(self) -> None:
cast(WarmLambdaRuntime, self.lambda_runtime).clean_running_containers_and_related_resources()
cast(RefreshableSamFunctionProvider, self._function_provider).stop_observer()

def _add_account_id_to_global(self) -> None:
"""
Attempts to get the Account ID from the current session
If there is no current session, the standard parameter override for
AWS::AccountId is used
"""
client_provider = get_boto_client_provider_with_config(region=self._aws_region, profile=self._aws_profile)

sts = client_provider("sts")

try:
account_id = sts.get_caller_identity().get("Account")
if account_id:
if self._global_parameter_overrides is None:
self._global_parameter_overrides = {}
self._global_parameter_overrides["AWS::AccountId"] = account_id
except (NoCredentialsError, TokenRetrievalError, ClientError):
LOG.warning("No current session found, using default AWS::AccountId")

@property
def function_identifier(self) -> str:
"""
Expand Down
3 changes: 2 additions & 1 deletion samcli/lib/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from samcli.lib.utils.architecture import X86_64
from samcli.lib.utils.packagetype import IMAGE
from samcli.lib.utils.path_utils import check_path_valid_type
from samcli.local.apigw.route import Route

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -977,7 +978,7 @@ def get_function_build_info(
dockerfile = cast(str, metadata.get("Dockerfile", ""))
docker_context = cast(str, metadata.get("DockerContext", ""))
buildable = dockerfile and docker_context
loadable = imageuri and Path(imageuri).is_file()
loadable = imageuri and check_path_valid_type(imageuri) and Path(imageuri).is_file()
if not buildable and not loadable:
LOG.debug(
"Skip Building %s function, as it is missing either Dockerfile or DockerContext "
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/providers/sam_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _extract_authorizers_from_props(logical_id: str, auth: dict, collector: ApiC
authorizers: Dict[str, Authorizer] = {}

for auth_name, auth_props in auth.get(SamApiProvider._AUTHORIZERS, {}).items():
authorizer_type = auth_props.get(SamApiProvider._FUNCTION_TYPE, LambdaAuthorizer.TOKEN)
authorizer_type = auth_props.get(SamApiProvider._FUNCTION_TYPE, LambdaAuthorizer.TOKEN.upper())
identity_object = auth_props.get(SamApiProvider._IDENTITY, {})

function_arn = auth_props.get(SamApiProvider._FUNCTION_ARN)
Expand Down
3 changes: 2 additions & 1 deletion samcli/lib/providers/sam_function_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from samcli.lib.utils.colors import Colored, Colors
from samcli.lib.utils.file_observer import FileObserver
from samcli.lib.utils.packagetype import IMAGE, ZIP
from samcli.lib.utils.path_utils import check_path_valid_type
from samcli.lib.utils.resources import (
AWS_LAMBDA_FUNCTION,
AWS_LAMBDA_LAYERVERSION,
Expand Down Expand Up @@ -447,7 +448,7 @@ def _build_function_configuration(
LOG.debug("--base-dir is not presented, adjusting uri %s relative to %s", codeuri, stack.location)
codeuri = SamLocalStackProvider.normalize_resource_path(stack.location, codeuri)

if imageuri and codeuri != ".":
if imageuri and check_path_valid_type(imageuri) and codeuri != ".":
normalized_image_uri = SamLocalStackProvider.normalize_resource_path(stack.location, imageuri)
if Path(normalized_image_uri).is_file():
LOG.debug("--base-dir is not presented, adjusting uri %s relative to %s", codeuri, stack.location)
Expand Down
23 changes: 23 additions & 0 deletions samcli/lib/utils/path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
Common Path related utilities
"""

import logging
import os
from pathlib import PureWindowsPath

LOG = logging.getLogger(__name__)


def convert_path_to_unix_path(path: str) -> str:
"""
Expand All @@ -19,3 +23,22 @@ def convert_path_to_unix_path(path: str) -> str:
the path in unix format
"""
return PureWindowsPath(path).as_posix()


def check_path_valid_type(path) -> bool:
"""
Checks the input to see if is a valid type to be a path, returning false if otherwise
Parameters
----------
path: str
the path to be checked
Returns
-------
bool
if the input is a valid path type
"""
if isinstance(path, (bytes, str, os.PathLike, int)):
return True
LOG.debug("Type error when trying to use input {} as Path, not string, int, bytes or os.PathLike ".format(path))
return False
5 changes: 1 addition & 4 deletions samcli/local/docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ def is_docker_reachable(docker_client):
:param docker_client : docker.from_env() - docker client object
:returns True, if Docker is available, False otherwise.
"""
errors = (
docker.errors.APIError,
requests.exceptions.ConnectionError,
)
errors = (docker.errors.APIError, requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout)
if platform.system() == "Windows":
import pywintypes # pylint: disable=import-error

Expand Down
2 changes: 1 addition & 1 deletion samcli/runtime_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app_template_repo_commit": "653b80818da99772e46d9dd72ba0e31e5c0263aa"
"app_template_repo_commit": "7455b202735c302bf37b57c99774c513bbe68069"
}
10 changes: 8 additions & 2 deletions schema/samcli.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,10 @@
},
"tags": {
"title": "tags",
"type": "array",
"type": [
"array",
"string"
],
"description": "List of tags to associate with the stack.",
"items": {
"type": "string"
Expand Down Expand Up @@ -1731,7 +1734,10 @@
},
"tags": {
"title": "tags",
"type": "array",
"type": [
"array",
"string"
],
"description": "List of tags to associate with the stack.",
"items": {
"type": "string"
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/deploy/test_deploy_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ def test_deploy_without_s3_bucket(self, template_file):
deploy_process_execute.stderr,
)

def test_deploy_with_no_resolve_s3_option(self):
template_path = self.test_data_path.joinpath("aws-serverless-function.yaml")

stack_name = self._method_to_stack_name(self.id())

deploy_command_list = self.get_deploy_command_list(
template_file=template_path,
stack_name=stack_name,
capabilities="CAPABILITY_IAM",
s3_prefix=self.s3_prefix,
force_upload=True,
notification_arns=self.sns_arn,
parameter_overrides="Parameter=Clarity",
kms_key_id=self.kms_key,
no_execute_changeset=False,
tags="integ=true clarity=yes foo_bar=baz",
confirm_changeset=False,
)

deploy_command_list.append("--no-resolve-s3")

deploy_process_execute = self.run_command(deploy_command_list)
# Error asking for s3 bucket
self.assertEqual(deploy_process_execute.process.returncode, 1)
self.assertIn(
bytes(
f"S3 Bucket not specified, use --s3-bucket to specify a bucket name, or use --resolve-s3 \
to create a managed default bucket, or run sam deploy --guided",
encoding="utf-8",
),
deploy_process_execute.stderr,
)

@parameterized.expand(["aws-serverless-function.yaml", "cdk_v1_synthesized_template_zip_functions.json"])
def test_deploy_without_stack_name(self, template_file):
template_path = self.test_data_path.joinpath(template_file)
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/local/invoke/invoke_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,14 @@ def run_command(self, command_list, env=None, cwd=None):
except TimeoutExpired:
process.kill()
raise


class IntegrationCliIntegBase(InvokeIntegBase):
def assert_is_account_id_valid(self, account_id: str):
try:
int(account_id)
except ValueError:
self.fail(f"Account ID '{account_id}' is not a valid number")

# AWS account IDs have length of 12
self.assertEqual(len(account_id), 12)
10 changes: 5 additions & 5 deletions tests/integration/local/invoke/test_integration_cli_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest
import docker

from .invoke_integ_base import InvokeIntegBase
from tests.integration.local.invoke.invoke_integ_base import IntegrationCliIntegBase, InvokeIntegBase
from tests.testing_utils import IS_WINDOWS, RUNNING_ON_CI, CI_OVERRIDE

from pathlib import Path
Expand All @@ -26,7 +26,7 @@
((IS_WINDOWS and RUNNING_ON_CI) and not CI_OVERRIDE),
"Skip build tests on windows when running in CI unless overridden",
)
class TestSamPython36HelloWorldIntegrationImages(InvokeIntegBase):
class TestSamPython36HelloWorldIntegrationImages(IntegrationCliIntegBase):
template = Path("template_image.yaml")

@classmethod
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_invoke_with_env_using_parameters(self):
environ = json.loads(process_stdout.decode("utf-8"))

self.assertEqual(environ["Region"], "us-east-1")
self.assertEqual(environ["AccountId"], "123456789012")
self.assert_is_account_id_valid(environ["AccountId"])
self.assertEqual(environ["Partition"], "aws")
self.assertEqual(environ["StackName"], "local")
self.assertEqual(
Expand All @@ -289,7 +289,7 @@ def test_invoke_with_env_using_parameters(self):

@pytest.mark.flaky(reruns=3)
def test_invoke_with_env_using_parameters_with_custom_region(self):
custom_region = "my-custom-region"
custom_region = "us-west-2"

command_list = InvokeIntegBase.get_command_list(
"EchoEnvWithParameters", template_path=self.template_path, event_path=self.event_path, region=custom_region
Expand All @@ -309,7 +309,7 @@ def test_invoke_with_env_using_parameters_with_custom_region(self):

@pytest.mark.flaky(reruns=3)
def test_invoke_with_env_with_aws_creds(self):
custom_region = "my-custom-region"
custom_region = "us-west-2"
key = "key"
secret = "secret"
session = "session"
Expand Down
Loading

0 comments on commit 16d748b

Please sign in to comment.