Description
Description:
When I use sam build
or sam local invoke
to build or locally debug a lambda function in a solution with a nuget.config file, I get a NuGet error which comes from the build step where Amazon.Lambda.Tools is installed. This only happens with the sam
cli commands. When I build and/or restore with dotnet
, no error occurs. We have a number of libraries in a private Azure Artifacts feed which need to be used with our solution so not using a private NuGet feed is not an option. This error originally popped up while I was trying to upgrade a stack to use .NET 6 from .NET 3.1. The whole build and invoke process was working correctly previously but, after upgrading the .NET SDK and the SAM CLI, all of a sudden the sam cli commands started having errors. I am pretty sure that I have isolated this down to an issue with the sam cli.
This seems like it might be related to #1970 but I'm not sure.
I have tried using the same nuget.config file in another "non-sam" project and I am able to use and retrieve packages from the private Azure feed without any issues.
Here is the nuget.config file's contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="PrivateAzureNuget" value="https://pkgs.dev.azure.com/myorg/<org-guid-here>/_packaging/MyProjectNuget/nuget/v3/index.json" />
</packageSources>
</configuration>
Steps to reproduce:
- Create a brand new stack with
sam init
- Build the stack with
sam build
. The stack builds without any problems. - Add a custom nuget.config file. Make sure that the default NuGet feed at https://api.nuget.org/v3/index.json is included.
- Do not add private feeds yet.
- Build the stack with
sam build
. The stack builds without any problems. - Add a private NuGet feed to the nuget.config file below the default NuGet feed.
- Build the stack with
sam build
. The stack has an error.
In the example above, I am not even referencing any of the libraries from the private NuGet feed; just the presence of the private NuGet feed in the nuget.config file causes this issue to occur.
Observed result:
user@buildmachine:~/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack$ sam build --debug
2023-11-18 17:15:25,562 | Config file location: /home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/samconfig.toml
2023-11-18 17:15:25,566 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at
'/home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/samconfig.toml'...
2023-11-18 17:15:25,568 | Configuration values successfully loaded.
2023-11-18 17:15:25,569 | Configuration values are: {'stack_name': 'NewTestDataProcStack', 'cached': True, 'parallel': True}
2023-11-18 17:15:25,575 | Using SAM Template at /home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/template.yaml
2023-11-18 17:15:25,608 | Using config file: samconfig.toml, config environment: default
2023-11-18 17:15:25,618 | Expand command line arguments to:
2023-11-18 17:15:25,619 | --template_file=/home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/template.yaml --parallel --mount_with=READ
--build_dir=.aws-sam/build --cache_dir=.aws-sam/cache --cached
2023-11-18 17:15:25,977 | 'build' command is called
2023-11-18 17:15:25,979 | Starting Build use cache
2023-11-18 17:15:25,982 | No Parameters detected in the template
2023-11-18 17:15:26,023 | There is no customer defined id or cdk path defined for resource helloFromLambdaFunction, so we will use the resource logical id as the resource id
2023-11-18 17:15:26,025 | 0 stacks found in the template
2023-11-18 17:15:26,026 | No Parameters detected in the template
2023-11-18 17:15:26,047 | There is no customer defined id or cdk path defined for resource helloFromLambdaFunction, so we will use the resource logical id as the resource id
2023-11-18 17:15:26,053 | 1 resources found in the stack
2023-11-18 17:15:26,055 | Found Serverless function with name='helloFromLambdaFunction' and CodeUri='./src/NewTestDataProcStack/'
2023-11-18 17:15:26,057 | --base-dir is not presented, adjusting uri ./src/NewTestDataProcStack/ relative to
/home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/template.yaml
2023-11-18 17:15:26,062 | 1 resources found in the stack
2023-11-18 17:15:26,064 | Found Serverless function with name='helloFromLambdaFunction' and CodeUri='./src/NewTestDataProcStack/'
2023-11-18 17:15:26,067 | Instantiating build definitions
2023-11-18 17:15:26,082 | Same function build definition found, adding function (Previous: BuildDefinition(dotnet6,
/home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/src/NewTestDataProcStack, Zip, , f51ff532-603c-4dae-801e-744661166ac2, {}, {}, x86_64, []), Current:
BuildDefinition(dotnet6, /home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/src/NewTestDataProcStack, Zip, , ed2961a9-c098-44ca-a640-90a7ae823648, {}, {},
x86_64, []), Function: Function(function_id='helloFromLambdaFunction', name='helloFromLambdaFunction', functionname='helloFromLambdaFunction', runtime='dotnet6', memory=256, timeout=100,
handler='NewTestDataProcStack::NewTestDataProcStack.Function::FunctionHandler', imageuri=None, packagetype='Zip', imageconfig=None,
codeuri='/home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/src/NewTestDataProcStack', environment=None, rolearn=None, layers=[], events=None,
metadata={'SamResourceId': 'helloFromLambdaFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], function_url_config=None,
function_build_info=<FunctionBuildInfo.BuildableZip: ('BuildableZip', 'Regular ZIP function which can be build with SAM CLI')>, stack_path='', runtime_management_config=None,
logging_config=None))
2023-11-18 17:15:26,104 | Async execution started
2023-11-18 17:15:26,106 | Invoking function functools.partial(<bound method ParallelBuildStrategy.build_single_function_definition of <samcli.lib.build.build_strategy.ParallelBuildStrategy
object at 0x7fc958f26450>>, <samcli.lib.build.build_graph.FunctionBuildDefinition object at 0x7fc958f27850>)
2023-11-18 17:15:26,133 | Running incremental build for runtime dotnet6 for following resources (helloFromLambdaFunction)
2023-11-18 17:15:26,134 | Waiting for async results
2023-11-18 17:15:26,180 | Cache is invalid, running build and copying resources for following functions (helloFromLambdaFunction)
2023-11-18 17:15:26,182 | Building codeuri: /home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/src/NewTestDataProcStack runtime: dotnet6 metadata: {}
architecture: x86_64 functions: helloFromLambdaFunction
2023-11-18 17:15:26,193 | Building to following folder /home/user/Dev/testSAMHelloWorld/NewTestDataProcStack/NewTestDataProcStack/.aws-sam/build/helloFromLambdaFunction
2023-11-18 17:15:26,195 | Loading workflow module 'aws_lambda_builders.workflows'
2023-11-18 17:15:26,199 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
2023-11-18 17:15:26,211 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2023-11-18 17:15:26,217 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
2023-11-18 17:15:26,245 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
2023-11-18 17:15:26,250 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2023-11-18 17:15:26,254 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2023-11-18 17:15:26,271 | Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
2023-11-18 17:15:26,275 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2023-11-18 17:15:26,289 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
2023-11-18 17:15:26,292 | Registering workflow 'RustCargoLambdaBuilder' with capability 'Capability(language='rust', dependency_manager='cargo', application_framework=None)'
2023-11-18 17:15:26,293 | Found workflow 'DotnetCliPackageBuilder' to support capabilities 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2023-11-18 17:15:26,295 | Running workflow 'DotnetCliPackageBuilder'
2023-11-18 17:15:26,296 | Running DotnetCliPackageBuilder:GlobalToolInstall
2023-11-18 17:15:26,297 | Entered synchronized block for updating Amazon.Lambda.Tools
2023-11-18 17:15:26,298 | Installing Amazon.Lambda.Tools Global Tool
2023-11-18 17:15:26,299 | executing dotnet: ['dotnet', 'tool', 'install', '-g', 'Amazon.Lambda.Tools', '--ignore-failed-sources']
2023-11-18 17:15:26,796 |
2023-11-18 17:15:26,798 | Error installing probably due to already installed. Attempt to update to latest version.
2023-11-18 17:15:26,801 | executing dotnet: ['dotnet', 'tool', 'update', '-g', 'Amazon.Lambda.Tools', '--ignore-failed-sources']
2023-11-18 17:15:34,102 | Terminating plugin 'CredentialProvider.Microsoft' due to an unrecoverable fault: NuGet.Protocol.Plugins.ProtocolException: A plugin protocol exception occurred.
---> NuGet.Protocol.Plugins.ProtocolException: The SSL connection could not be established, see inner exception.
at NuGet.Protocol.Plugins.OutboundRequestContext`1.HandleFault(Message fault)
at NuGet.Protocol.Plugins.MessageDispatcher.OnMessageReceived(Object sender, MessageEventArgs e)
at NuGet.Protocol.Plugins.Connection.OnMessageReceived(Object sender, MessageEventArgs e)
at NuGet.Protocol.Plugins.Receiver.FireMessageReceivedEvent(Message message)
at NuGet.Protocol.Plugins.StandardOutputReceiver.OnLineRead(Object sender, LineReadEventArgs e)
--- End of inner exception stack trace ---
/usr/share/dotnet/sdk/6.0.417/NuGet.targets(132,5): error : A task was canceled. [/tmp/9bd7a666-2737-4d4f-8602-167f2d2b2f74/restore.csproj]
2023-11-18 17:15:34,110 | DotnetCliPackageBuilder:GlobalToolInstall failed
Traceback (most recent call last):
File "aws_lambda_builders/workflows/dotnet_clipackage/actions.py", line 47, in execute
File "aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py", line 65, in run
aws_lambda_builders.workflows.dotnet_clipackage.dotnetcli.DotnetCLIExecutionError: Dotnet CLI Failed: Tool 'amazon.lambda.tools' is already installed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "aws_lambda_builders/workflows/dotnet_clipackage/actions.py", line 52, in execute
File "aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py", line 65, in run
aws_lambda_builders.workflows.dotnet_clipackage.dotnetcli.DotnetCLIExecutionError: Dotnet CLI Failed: Tool 'amazon.lambda.tools' failed to update due to the following:
The tool package could not be restored.
Tool 'amazon.lambda.tools' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "aws_lambda_builders/workflow.py", line 371, in run
File "aws_lambda_builders/workflows/dotnet_clipackage/actions.py", line 57, in execute
aws_lambda_builders.actions.ActionFailedError: Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: Dotnet CLI Failed: Tool 'amazon.lambda.tools' failed to update due to the
following:
The tool package could not be restored.
Tool 'amazon.lambda.tools' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
2023-11-18 17:15:34,138 | Exception raised during the execution
Build Failed
2023-11-18 17:15:34,141 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-11-18 17:15:34,304 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-11-18 17:15:34,304 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'b0c7f849-7f44-41f2-a85e-c91eacbb6b12', 'installationId': '11752e67-df08-4045-9099-f661e360e8ca',
'sessionId': '29a794b7-2ae3-4502-8d01-97a8cb646a5a', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.3', 'samcliVersion': '1.103.0', 'awsProfileProvided': False,
'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName':
'3eecfc43b8f9ce0236269f327f5ad04f1e82ac73b713b7b13e41086e67a2867c', 'initialCommit': None}, 'duration': 8532, 'exitReason': 'WorkflowFailedError', 'exitCode': 1}}]}
2023-11-18 17:15:34,306 | Unable to find Click Context for getting session_id.
2023-11-18 17:15:34,327 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'c2822087-3ba6-49bc-babc-cedab6735ae4', 'installationId': '11752e67-df08-4045-9099-f661e360e8ca',
'sessionId': '29a794b7-2ae3-4502-8d01-97a8cb646a5a', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.3', 'samcliVersion': '1.103.0', 'commandName': 'sam build',
'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '7d8da1646eb749979a84f1d7746a0ccf', 'time_stamp': '2023-11-19
01:15:25.562', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'fbca4a96a2df4fe4b0469ed9f3b97bef', 'time_stamp': '2023-11-19
01:15:25.608', 'exception_name': None}, {'event_name': 'BuildFunctionRuntime', 'event_value': 'dotnet6', 'thread_id': '5cfe9c58e8474b54a34abb2908a7751f', 'time_stamp': '2023-11-19
01:15:26.067', 'exception_name': None}, {'event_name': 'BuildWorkflowUsed', 'event_value': 'dotnet-cli-package', 'thread_id': '3cdfda034a434b38a0c2c30588a69f7d', 'time_stamp': '2023-11-19
01:15:26.194', 'exception_name': None}]}}}]}
2023-11-18 17:15:34,739 | Telemetry response: 200
Error: DotnetCliPackageBuilder:GlobalToolInstall - Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: Dotnet CLI Failed: Tool 'amazon.lambda.tools' failed to update due to the following:
The tool package could not be restored.
Tool 'amazon.lambda.tools' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
2023-11-18 17:15:34,743 | Telemetry response: 200
Expected result:
To be able to use private feeds in a nuget.config file and have sam build
and sam local invoke
work.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Linux Mint 20.3 (based on Ubuntu 20.04)
sam --version
:SAM CLI, version 1.103.0
- AWS region: us-west-1
{
"version": "1.103.0",
"system": {
"python": "3.11.3",
"os": "Linux-5.4.0-166-generic-x86_64-with-glibc2.31"
},
"additional_dependencies": {
"docker_engine": "24.0.7",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}