Skip to content

Commit 750010e

Browse files
authoredOct 29, 2024
Merge from aws/aws-sam-cli/develop
2 parents 221e6e4 + 6a4e1ba commit 750010e

21 files changed

+1094
-834
lines changed
 

‎.gitignore

+2-6
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,8 @@ coverage.xml
412412

413413
# Temporary scratch directory used by the tests
414414
tests/integration/buildcmd/scratch
415-
tests/integration/testdata/buildcmd/Dotnet6/bin
416-
tests/integration/testdata/buildcmd/Dotnet6/obj
417-
tests/integration/testdata/buildcmd/Dotnet7/bin
418-
tests/integration/testdata/buildcmd/Dotnet7/obj
419-
tests/integration/testdata/buildcmd/Dotnet8/bin
420-
tests/integration/testdata/buildcmd/Dotnet8/obj
415+
tests/integration/testdata/buildcmd/Dotnet*/bin
416+
tests/integration/testdata/buildcmd/Dotnet*/obj
421417
tests/integration/testdata/invoke/credential_tests/inprocess/dotnet/STS/obj
422418
tests/integration/testdata/sync/code/after/dotnet_function/src/HelloWorld/obj/
423419
tests/integration/testdata/sync/code/before/dotnet_function/src/HelloWorld/obj/

‎installer/pyinstaller/build-linux.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [ "$python_version" = "" ]; then
1616
fi
1717

1818
if [ "$openssl_version" = "" ]; then
19-
openssl_version="3.0.15";
19+
openssl_version="3.3.1";
2020
fi
2121

2222
if [ "$zlib_version" = "" ]; then

‎installer/pyinstaller/build-mac.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [ "$python_library_zip_filename" = "" ]; then
3030
fi
3131

3232
if [ "$openssl_version" = "" ]; then
33-
openssl_version="3.0.15";
33+
openssl_version="3.3.1";
3434
fi
3535

3636
if [ "$python_version" = "" ]; then

‎requirements/base.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ dateparser~=1.2
1313
requests~=2.32.3
1414
aws_lambda_builders==1.50.0
1515
tomlkit==0.13.2
16-
watchdog==5.0.3; python_version>"3.8"
17-
watchdog==4.0.2; python_version<="3.8"
16+
# NOTE: For supporting watchdog in Python3.8, version is pinned to 4.0.2 as
17+
# version 5.0.2 introduced some breaking changes for versions > Python3.8
18+
watchdog==4.0.2
1819

1920
rich~=13.9.2
2021
pyopenssl~=24.2.1
@@ -30,7 +31,7 @@ regex!=2021.10.8
3031
tzlocal==5.2
3132

3233
#Adding cfn-lint dependency for SAM validate
33-
cfn-lint~=1.16.0
34+
cfn-lint~=1.17.2
3435

3536
# Type checking boto3 objects
36-
boto3-stubs[apigateway,cloudformation,ecr,iam,lambda,s3,schemas,secretsmanager,signer,stepfunctions,sts,xray,sqs,kinesis]==1.35.32
37+
boto3-stubs[apigateway,cloudformation,ecr,iam,lambda,s3,schemas,secretsmanager,signer,stepfunctions,sts,xray,sqs,kinesis]==1.35.49

‎requirements/dev.txt

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
-r pre-dev.txt
22

3-
coverage==7.6.1
3+
coverage==7.6.4; python_version>="3.9"
4+
coverage==7.6.1; python_version<"3.9"
45
pytest-cov==5.0.0
56

67

78
# type checking and related stubs
89
# mypy adds new rules in new minor versions, which could cause our PR check to fail
910
# here we fix its version and upgrade it manually in the future
1011
mypy==1.11.2
11-
types-pywin32==306.0.0.20240822
12+
types-pywin32==308.0.0.20241025
1213
types-PyYAML==6.0.12.20240917
1314
types-chevron==0.14.2.20240310
14-
types-psutil==6.0.0.20240901
15-
types-setuptools==75.1.0.20240917
15+
types-psutil==6.1.0.20241022
16+
types-setuptools==75.2.0.20241025
1617
types-Pygments==2.18.0.20240506
1718
types-colorama==0.4.15.20240311
1819
types-dateparser==1.2.0.20240420
@@ -22,7 +23,7 @@ types-pyOpenSSL==24.1.0.20240722
2223
# lucashuy: pin `types-request` based on the Python version since newer versions of
2324
# the types require a newer version of requests, which is only installed in newer versions of Python
2425
types-requests==2.31.0.6; python_version<"3.10"
25-
types-requests==2.32.0.20240914; python_version>="3.10"
26+
types-requests==2.32.0.20241016; python_version>="3.10"
2627
types-urllib3==1.26.25.14
2728

2829
# Test requirements
@@ -41,5 +42,6 @@ pytest-json-report-wip==1.5.1
4142
filelock==3.16.1
4243

4344
# formatter
44-
black==24.8.0
45-
psutil==6.0.0
45+
black==24.10.0; python_version>="3.9"
46+
black==24.8.0; python_version<"3.9"
47+
psutil==6.1.0

‎requirements/pyinstaller-build.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Executable binary builder requirements
22
setuptools==75.1.0
3-
pyinstaller==6.10.0
3+
pyinstaller==6.11.0

‎requirements/reproducible-linux.txt

+319-307
Large diffs are not rendered by default.

‎requirements/reproducible-mac.txt

+180-165
Large diffs are not rendered by default.

‎requirements/reproducible-win.txt

+338-326
Large diffs are not rendered by default.

‎samcli/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
SAM CLI version
33
"""
44

5-
__version__ = "1.126.0"
5+
__version__ = "1.127.0"

‎samcli/commands/exceptions.py

+7
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,10 @@ class LinterRuleMatchedException(UserException):
152152
"""
153153
The linter matched a rule meaning that the template linting failed
154154
"""
155+
156+
157+
class PopularRuntimeNotFoundException(Exception):
158+
"""
159+
Exception thrown when we were not able to parse the SUPPORTED_RUNTIMES
160+
constant correctly for the latest runtime
161+
"""

‎samcli/commands/init/interactive_init_flow.py

+61-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
import logging
66
import pathlib
7+
import re
78
import tempfile
89
from typing import Optional, Tuple
910

1011
import click
1112
from botocore.exceptions import ClientError, WaiterError
1213

1314
from samcli.commands._utils.options import generate_next_command_recommendation
14-
from samcli.commands.exceptions import InvalidInitOptionException, SchemasApiException
15+
from samcli.commands.exceptions import InvalidInitOptionException, PopularRuntimeNotFoundException, SchemasApiException
1516
from samcli.commands.init.init_flow_helpers import (
1617
_get_image_from_runtime,
1718
_get_runtime_from_image,
@@ -28,6 +29,7 @@
2829
)
2930
from samcli.lib.config.samconfig import DEFAULT_CONFIG_FILE_NAME
3031
from samcli.lib.schemas.schemas_code_manager import do_download_source_code_binding, do_extract_and_merge_schemas_code
32+
from samcli.lib.utils.architecture import SUPPORTED_RUNTIMES
3133
from samcli.lib.utils.osutils import remove
3234
from samcli.lib.utils.packagetype import IMAGE, ZIP
3335
from samcli.local.common.runtime_template import (
@@ -323,6 +325,60 @@ def _generate_from_use_case(
323325
)
324326

325327

328+
def _get_latest_python_runtime() -> str:
329+
"""
330+
Returns the latest support version of Python
331+
SAM CLI supports
332+
333+
Returns
334+
-------
335+
str:
336+
The name of the latest Python runtime (ex. "python3.12")
337+
"""
338+
latest_major = 0
339+
latest_minor = 0
340+
341+
compiled_regex = re.compile(r"python(.*?)\.(.*)")
342+
343+
for runtime in SUPPORTED_RUNTIMES:
344+
if not runtime.startswith("python"):
345+
continue
346+
347+
# python3.12 => 3.12 => (3, 12)
348+
version_match = re.match(compiled_regex, runtime)
349+
350+
if not version_match:
351+
LOG.debug(f"Failed to match version while checking {runtime}")
352+
continue
353+
354+
matched_groups = version_match.groups()
355+
356+
try:
357+
version_major = int(matched_groups[0])
358+
version_minor = int(matched_groups[1])
359+
except (ValueError, IndexError):
360+
LOG.debug(f"Failed to parse version while checking {runtime}")
361+
continue
362+
363+
if version_major > latest_major:
364+
latest_major = version_major
365+
latest_minor = version_minor
366+
elif version_major == latest_major:
367+
latest_minor = version_minor if version_minor > latest_minor else latest_minor
368+
369+
if not latest_major:
370+
# major version is still 0, assume that something went wrong
371+
# this in theory should not happen as long as Python is
372+
# listed in the SUPPORTED_RUNTIMES constant
373+
raise PopularRuntimeNotFoundException("Was unable to search for the latest supported runtime")
374+
375+
selected_version = f"python{latest_major}.{latest_minor}"
376+
377+
LOG.debug(f"Using {selected_version} as the latest runtime version")
378+
379+
return selected_version
380+
381+
326382
def _generate_default_hello_world_application(
327383
use_case: str,
328384
package_type: Optional[str],
@@ -356,8 +412,10 @@ def _generate_default_hello_world_application(
356412
"""
357413
is_package_type_image = bool(package_type == IMAGE)
358414
if use_case == "Hello World Example" and not (runtime or base_image or is_package_type_image or dependency_manager):
359-
if click.confirm("\nUse the most popular runtime and package type? (Python and zip)"):
360-
runtime, package_type, dependency_manager, pt_explicit = "python3.9", ZIP, "pip", True
415+
latest_python = _get_latest_python_runtime()
416+
417+
if click.confirm(f"\nUse the most popular runtime and package type? ({latest_python} and zip)"):
418+
runtime, package_type, dependency_manager, pt_explicit = _get_latest_python_runtime(), ZIP, "pip", True
361419
return (runtime, package_type, dependency_manager, pt_explicit)
362420

363421

‎samcli/commands/local/cli_common/invoke_context.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from pathlib import Path
1111
from typing import Any, Dict, List, Optional, TextIO, Tuple, Type, cast
1212

13-
from botocore.exceptions import ClientError, NoCredentialsError, TokenRetrievalError
14-
1513
from samcli.commands._utils.template import TemplateFailedParsingException, TemplateNotFoundException
1614
from samcli.commands.exceptions import ContainersInitializationException
1715
from samcli.commands.local.cli_common.user_exceptions import DebugContextException, InvokeContextException
@@ -365,7 +363,7 @@ def _add_account_id_to_global(self) -> None:
365363
if self._global_parameter_overrides is None:
366364
self._global_parameter_overrides = {}
367365
self._global_parameter_overrides["AWS::AccountId"] = account_id
368-
except (NoCredentialsError, TokenRetrievalError, ClientError):
366+
except Exception:
369367
LOG.warning("No current session found, using default AWS::AccountId")
370368

371369
@property

‎samcli/lib/build/workflow_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def get_workflow_config(
148148
selectors_by_build_method = {
149149
"makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG),
150150
"dotnet7": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
151+
"dotnet": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
151152
"rust-cargolambda": BasicWorkflowSelector(RUST_CARGO_LAMBDA_CONFIG),
152153
}
153154

‎samcli/local/apigw/local_apigw_service.py

+5
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ def _request_handler(self, **kwargs):
718718
LOG.error("Lambda authorizer failed to invoke successfully: %s", str(lambda_authorizer_exception))
719719

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

723728
endpoint_service_error = None

‎tests/integration/buildcmd/test_build_cmd_dotnet.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegDotnetBase):
2525
[
2626
("provided.al2", "Dotnet7", None, None),
2727
("provided.al2", "Dotnet7", None, MountMode.WRITE),
28+
("provided.al2", "Dotnet", None, None),
2829
]
2930
)
3031
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
@@ -36,7 +37,10 @@ def test_dotnet_al2(self, runtime, code_uri, mode, mount_mode):
3637
"Architectures": "x86_64",
3738
}
3839

39-
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")
40+
if mode == "Dotnet":
41+
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet.yaml")
42+
else:
43+
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")
4044

4145
self.validate_build_command(overrides, mode, mount_mode)
4246
self.validate_build_artifacts(self.EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<OutputType>exe</OutputType>
7+
<AssemblyName>bootstrap</AssemblyName>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<SelfContained>true</SelfContained>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
14+
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
15+
<PackageReference Include="Amazon.Lambda.Core" Version="2.3.0" />
16+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
17+
</ItemGroup>
18+
19+
</Project>
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Amazon.Lambda.APIGatewayEvents;
2+
using Amazon.Lambda.Core;
3+
using Amazon.Lambda.RuntimeSupport;
4+
using Amazon.Lambda.Serialization.SystemTextJson;
5+
using System.Text.Json.Serialization;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
using System.Net.Http;
11+
using System.Net.Http.Headers;
12+
13+
namespace HelloWorld;
14+
15+
public class Function
16+
{
17+
/// <summary>
18+
/// The main entry point for the custom runtime.
19+
/// </summary>
20+
/// <param name="args"></param>
21+
private static async Task Main(string[] args)
22+
{
23+
Func<APIGatewayHttpApiV2ProxyRequest, ILambdaContext, string> handler = FunctionHandler;
24+
await LambdaBootstrapBuilder.Create(handler, new SourceGeneratorLambdaJsonSerializer<MyCustomJsonSerializerContext>())
25+
.Build()
26+
.RunAsync();
27+
}
28+
29+
public static string FunctionHandler(APIGatewayHttpApiV2ProxyRequest apigProxyEvent, ILambdaContext context)
30+
{
31+
return "{'message': 'Hello World'}";
32+
}
33+
}
34+
35+
[JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))]
36+
public partial class MyCustomJsonSerializerContext : JsonSerializerContext
37+
{
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Information" : [
3+
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
4+
"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.",
5+
6+
"dotnet lambda help",
7+
8+
"All the command line options for the Lambda command can be specified in this file."
9+
],
10+
11+
"profile":"",
12+
"region" : "",
13+
"configuration": "Release",
14+
"function-runtime":"provided.al2023",
15+
"function-memory-size" : 256,
16+
"function-timeout" : 30,
17+
"function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler"
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
iAWSTemplateFormatVersion : '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Parameteres:
5+
Runtime:
6+
Type: String
7+
CodeUri:
8+
Type: String
9+
Handler:
10+
Type: String
11+
12+
Resources:
13+
14+
Function:
15+
Type: AWS::Serverless::Function
16+
Properties:
17+
Handler: !Ref Handler
18+
Runtime: !Ref Runtime
19+
CodeUri: !Ref CodeUri
20+
Timeout: 600
21+
Metadata:
22+
BuildMethod: dotnet
23+
24+
OtherRelativePathResource:
25+
Type: AWS::ApiGateway::RestApi
26+
Properties:
27+
BodyS3Location: SomeRelativePath
28+
29+
GlueResource:
30+
Type: AWS::Glue::Job
31+
Properties:
32+
Command:
33+
ScriptLocation: SomeRelativePath
34+
35+
ExampleNestedStack:
36+
Type: AWS::CloudFormation::Stack
37+
Properties:
38+
TemplateURL: https://s3.amazonaws.com/examplebucket/exampletemplate.yml

0 commit comments

Comments
 (0)
Failed to load comments.