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 Oct 29, 2024
2 parents 221e6e4 + 6a4e1ba commit 750010e
Show file tree
Hide file tree
Showing 21 changed files with 1,094 additions and 834 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,8 @@ coverage.xml

# Temporary scratch directory used by the tests
tests/integration/buildcmd/scratch
tests/integration/testdata/buildcmd/Dotnet6/bin
tests/integration/testdata/buildcmd/Dotnet6/obj
tests/integration/testdata/buildcmd/Dotnet7/bin
tests/integration/testdata/buildcmd/Dotnet7/obj
tests/integration/testdata/buildcmd/Dotnet8/bin
tests/integration/testdata/buildcmd/Dotnet8/obj
tests/integration/testdata/buildcmd/Dotnet*/bin
tests/integration/testdata/buildcmd/Dotnet*/obj
tests/integration/testdata/invoke/credential_tests/inprocess/dotnet/STS/obj
tests/integration/testdata/sync/code/after/dotnet_function/src/HelloWorld/obj/
tests/integration/testdata/sync/code/before/dotnet_function/src/HelloWorld/obj/
Expand Down
2 changes: 1 addition & 1 deletion installer/pyinstaller/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ "$python_version" = "" ]; then
fi

if [ "$openssl_version" = "" ]; then
openssl_version="3.0.15";
openssl_version="3.3.1";
fi

if [ "$zlib_version" = "" ]; then
Expand Down
2 changes: 1 addition & 1 deletion installer/pyinstaller/build-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [ "$python_library_zip_filename" = "" ]; then
fi

if [ "$openssl_version" = "" ]; then
openssl_version="3.0.15";
openssl_version="3.3.1";
fi

if [ "$python_version" = "" ]; then
Expand Down
9 changes: 5 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ dateparser~=1.2
requests~=2.32.3
aws_lambda_builders==1.50.0
tomlkit==0.13.2
watchdog==5.0.3; python_version>"3.8"
watchdog==4.0.2; python_version<="3.8"
# NOTE: For supporting watchdog in Python3.8, version is pinned to 4.0.2 as
# version 5.0.2 introduced some breaking changes for versions > Python3.8
watchdog==4.0.2

rich~=13.9.2
pyopenssl~=24.2.1
Expand All @@ -30,7 +31,7 @@ regex!=2021.10.8
tzlocal==5.2

#Adding cfn-lint dependency for SAM validate
cfn-lint~=1.16.0
cfn-lint~=1.17.2

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

coverage==7.6.1
coverage==7.6.4; python_version>="3.9"
coverage==7.6.1; python_version<"3.9"
pytest-cov==5.0.0


# type checking and related stubs
# mypy adds new rules in new minor versions, which could cause our PR check to fail
# here we fix its version and upgrade it manually in the future
mypy==1.11.2
types-pywin32==306.0.0.20240822
types-pywin32==308.0.0.20241025
types-PyYAML==6.0.12.20240917
types-chevron==0.14.2.20240310
types-psutil==6.0.0.20240901
types-setuptools==75.1.0.20240917
types-psutil==6.1.0.20241022
types-setuptools==75.2.0.20241025
types-Pygments==2.18.0.20240506
types-colorama==0.4.15.20240311
types-dateparser==1.2.0.20240420
Expand All @@ -22,7 +23,7 @@ types-pyOpenSSL==24.1.0.20240722
# 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.20240914; python_version>="3.10"
types-requests==2.32.0.20241016; python_version>="3.10"
types-urllib3==1.26.25.14

# Test requirements
Expand All @@ -41,5 +42,6 @@ pytest-json-report-wip==1.5.1
filelock==3.16.1

# formatter
black==24.8.0
psutil==6.0.0
black==24.10.0; python_version>="3.9"
black==24.8.0; python_version<"3.9"
psutil==6.1.0
2 changes: 1 addition & 1 deletion requirements/pyinstaller-build.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Executable binary builder requirements
setuptools==75.1.0
pyinstaller==6.10.0
pyinstaller==6.11.0
626 changes: 319 additions & 307 deletions requirements/reproducible-linux.txt

Large diffs are not rendered by default.

345 changes: 180 additions & 165 deletions requirements/reproducible-mac.txt

Large diffs are not rendered by default.

664 changes: 338 additions & 326 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.126.0"
__version__ = "1.127.0"
7 changes: 7 additions & 0 deletions samcli/commands/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,10 @@ class LinterRuleMatchedException(UserException):
"""
The linter matched a rule meaning that the template linting failed
"""


class PopularRuntimeNotFoundException(Exception):
"""
Exception thrown when we were not able to parse the SUPPORTED_RUNTIMES
constant correctly for the latest runtime
"""
64 changes: 61 additions & 3 deletions samcli/commands/init/interactive_init_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import logging
import pathlib
import re
import tempfile
from typing import Optional, Tuple

import click
from botocore.exceptions import ClientError, WaiterError

from samcli.commands._utils.options import generate_next_command_recommendation
from samcli.commands.exceptions import InvalidInitOptionException, SchemasApiException
from samcli.commands.exceptions import InvalidInitOptionException, PopularRuntimeNotFoundException, SchemasApiException
from samcli.commands.init.init_flow_helpers import (
_get_image_from_runtime,
_get_runtime_from_image,
Expand All @@ -28,6 +29,7 @@
)
from samcli.lib.config.samconfig import DEFAULT_CONFIG_FILE_NAME
from samcli.lib.schemas.schemas_code_manager import do_download_source_code_binding, do_extract_and_merge_schemas_code
from samcli.lib.utils.architecture import SUPPORTED_RUNTIMES
from samcli.lib.utils.osutils import remove
from samcli.lib.utils.packagetype import IMAGE, ZIP
from samcli.local.common.runtime_template import (
Expand Down Expand Up @@ -323,6 +325,60 @@ def _generate_from_use_case(
)


def _get_latest_python_runtime() -> str:
"""
Returns the latest support version of Python
SAM CLI supports
Returns
-------
str:
The name of the latest Python runtime (ex. "python3.12")
"""
latest_major = 0
latest_minor = 0

compiled_regex = re.compile(r"python(.*?)\.(.*)")

for runtime in SUPPORTED_RUNTIMES:
if not runtime.startswith("python"):
continue

# python3.12 => 3.12 => (3, 12)
version_match = re.match(compiled_regex, runtime)

if not version_match:
LOG.debug(f"Failed to match version while checking {runtime}")
continue

matched_groups = version_match.groups()

try:
version_major = int(matched_groups[0])
version_minor = int(matched_groups[1])
except (ValueError, IndexError):
LOG.debug(f"Failed to parse version while checking {runtime}")
continue

if version_major > latest_major:
latest_major = version_major
latest_minor = version_minor
elif version_major == latest_major:
latest_minor = version_minor if version_minor > latest_minor else latest_minor

if not latest_major:
# major version is still 0, assume that something went wrong
# this in theory should not happen as long as Python is
# listed in the SUPPORTED_RUNTIMES constant
raise PopularRuntimeNotFoundException("Was unable to search for the latest supported runtime")

selected_version = f"python{latest_major}.{latest_minor}"

LOG.debug(f"Using {selected_version} as the latest runtime version")

return selected_version


def _generate_default_hello_world_application(
use_case: str,
package_type: Optional[str],
Expand Down Expand Up @@ -356,8 +412,10 @@ def _generate_default_hello_world_application(
"""
is_package_type_image = bool(package_type == IMAGE)
if use_case == "Hello World Example" and not (runtime or base_image or is_package_type_image or dependency_manager):
if click.confirm("\nUse the most popular runtime and package type? (Python and zip)"):
runtime, package_type, dependency_manager, pt_explicit = "python3.9", ZIP, "pip", True
latest_python = _get_latest_python_runtime()

if click.confirm(f"\nUse the most popular runtime and package type? ({latest_python} and zip)"):
runtime, package_type, dependency_manager, pt_explicit = _get_latest_python_runtime(), ZIP, "pip", True
return (runtime, package_type, dependency_manager, pt_explicit)


Expand Down
4 changes: 1 addition & 3 deletions samcli/commands/local/cli_common/invoke_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
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 Down Expand Up @@ -365,7 +363,7 @@ def _add_account_id_to_global(self) -> None:
if self._global_parameter_overrides is None:
self._global_parameter_overrides = {}
self._global_parameter_overrides["AWS::AccountId"] = account_id
except (NoCredentialsError, TokenRetrievalError, ClientError):
except Exception:
LOG.warning("No current session found, using default AWS::AccountId")

@property
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def get_workflow_config(
selectors_by_build_method = {
"makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG),
"dotnet7": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"dotnet": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"rust-cargolambda": BasicWorkflowSelector(RUST_CARGO_LAMBDA_CONFIG),
}

Expand Down
5 changes: 5 additions & 0 deletions samcli/local/apigw/local_apigw_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ def _request_handler(self, **kwargs):
LOG.error("Lambda authorizer failed to invoke successfully: %s", str(lambda_authorizer_exception))

if auth_service_error:
# Return the Flask service error if there is one, since these are the only exceptions
# we are anticipating from the authorizer, anything else indicates a local issue.
#
# Note that returning within a finally block will have the effect of swallowing
# any reraised exceptions.
return auth_service_error

endpoint_service_error = None
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/buildcmd/test_build_cmd_dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegDotnetBase):
[
("provided.al2", "Dotnet7", None, None),
("provided.al2", "Dotnet7", None, MountMode.WRITE),
("provided.al2", "Dotnet", None, None),
]
)
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
Expand All @@ -36,7 +37,10 @@ def test_dotnet_al2(self, runtime, code_uri, mode, mount_mode):
"Architectures": "x86_64",
}

self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")
if mode == "Dotnet":
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet.yaml")
else:
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")

self.validate_build_command(overrides, mode, mount_mode)
self.validate_build_artifacts(self.EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED)
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<OutputType>exe</OutputType>
<AssemblyName>bootstrap</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<SelfContained>true</SelfContained>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.3.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
</ItemGroup>

</Project>

38 changes: 38 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;
using System.Text.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;

namespace HelloWorld;

public class Function
{
/// <summary>
/// The main entry point for the custom runtime.
/// </summary>
/// <param name="args"></param>
private static async Task Main(string[] args)
{
Func<APIGatewayHttpApiV2ProxyRequest, ILambdaContext, string> handler = FunctionHandler;
await LambdaBootstrapBuilder.Create(handler, new SourceGeneratorLambdaJsonSerializer<MyCustomJsonSerializerContext>())
.Build()
.RunAsync();
}

public static string FunctionHandler(APIGatewayHttpApiV2ProxyRequest apigProxyEvent, ILambdaContext context)
{
return "{'message': 'Hello World'}";
}
}

[JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))]
public partial class MyCustomJsonSerializerContext : JsonSerializerContext
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Information" : [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",

"dotnet lambda help",

"All the command line options for the Lambda command can be specified in this file."
],

"profile":"",
"region" : "",
"configuration": "Release",
"function-runtime":"provided.al2023",
"function-memory-size" : 256,
"function-timeout" : 30,
"function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
iAWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameteres:
Runtime:
Type: String
CodeUri:
Type: String
Handler:
Type: String

Resources:

Function:
Type: AWS::Serverless::Function
Properties:
Handler: !Ref Handler
Runtime: !Ref Runtime
CodeUri: !Ref CodeUri
Timeout: 600
Metadata:
BuildMethod: dotnet

OtherRelativePathResource:
Type: AWS::ApiGateway::RestApi
Properties:
BodyS3Location: SomeRelativePath

GlueResource:
Type: AWS::Glue::Job
Properties:
Command:
ScriptLocation: SomeRelativePath

ExampleNestedStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.amazonaws.com/examplebucket/exampletemplate.yml
Loading

0 comments on commit 750010e

Please sign in to comment.