sam build disregards base-dir in 1.21.0
See original GitHub issueDescription:
It seems like sam v1.21.0 disregards the --base-dir flag given to ‘sam build’
Steps to reproduce:
I have $PWD/templates/template.yaml, with a function whose CodeUri is src/Function, which exists as $PWD/src/Function. I run:
sam build --template templates/template.yaml --region us-west-2 --base-dir .
… This succeeds in sam 1.20.0 but fails in 1.21.0 with a complaint about not finding templates/src/Function.
Observed result:
2021-03-15 16:05:25,713 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2021-03-15 16:05:25,714 | Using config file: samconfig.toml, config environment: default 2021-03-15 16:05:25,714 | Expand command line arguments to: 2021-03-15 16:05:25,714 | --template_file=/Users/matthew/dev/sam-example/templates/template.yaml --base_dir=. --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache 2021-03-15 16:05:25,781 | ‘build’ command is called 2021-03-15 16:05:25,786 | Collected default values for parameters: {‘StackTagName’: ‘sam-example’, ‘EnvironmentTagName’: ‘development’} 2021-03-15 16:05:25,813 | 1 stacks found in the template 2021-03-15 16:05:25,814 | Collected default values for parameters: {‘StackTagName’: ‘sam-example’, ‘EnvironmentTagName’: ‘development’} 2021-03-15 16:05:25,836 | 1 resources found in the stack 2021-03-15 16:05:25,836 | Collected default values for parameters: {‘StackTagName’: ‘sam-example’, ‘EnvironmentTagName’: ‘development’} 2021-03-15 16:05:25,875 | Found Serverless function with name=‘Function’ and CodeUri=‘src/Function’ 2021-03-15 16:05:25,876 | Collected default values for parameters: {‘StackTagName’: ‘sam-example’, ‘EnvironmentTagName’: ‘development’} 2021-03-15 16:05:25,902 | Instantiating build definitions 2021-03-15 16:05:25,906 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(nodejs14.x, /Users/matthew/dev/sam-example/templates/src/Function, Zip, , 4f88b5c7-100d-43ce-b15c-1f2186783794, {}, {}, []), Function: Function(name=‘Function’, functionname=‘local-Function’, runtime=‘nodejs14.x’, memory=128, timeout=30, handler=‘index.handler’, imageuri=None, packagetype=‘Zip’, imageconfig=None, codeuri=‘/Users/matthew/dev/sam-example/templates/src/Function’, environment=None, rolearn=None, layers=[], events=None, metadata=None, inlinecode=None, codesign_config_arn=None, stack_path=‘’)) 2021-03-15 16:05:25,908 | Building codeuri: /Users/matthew/dev/sam-example/templates/src/Function runtime: nodejs14.x metadata: {} functions: [‘Function’] 2021-03-15 16:05:25,908 | Building to following folder /Users/matthew/dev/sam-example/.aws-sam/build/Function 2021-03-15 16:05:25,909 | Loading workflow module ‘aws_lambda_builders.workflows’ 2021-03-15 16:05:25,914 | Registering workflow ‘PythonPipBuilder’ with capability ‘Capability(language=‘python’, dependency_manager=‘pip’, application_framework=None)’ 2021-03-15 16:05:25,916 | Registering workflow ‘NodejsNpmBuilder’ with capability ‘Capability(language=‘nodejs’, dependency_manager=‘npm’, application_framework=None)’ 2021-03-15 16:05:25,918 | Registering workflow ‘RubyBundlerBuilder’ with capability ‘Capability(language=‘ruby’, dependency_manager=‘bundler’, application_framework=None)’ 2021-03-15 16:05:25,920 | Registering workflow ‘GoDepBuilder’ with capability ‘Capability(language=‘go’, dependency_manager=‘dep’, application_framework=None)’ 2021-03-15 16:05:25,922 | Registering workflow ‘GoModulesBuilder’ with capability ‘Capability(language=‘go’, dependency_manager=‘modules’, application_framework=None)’ 2021-03-15 16:05:25,925 | Registering workflow ‘JavaGradleWorkflow’ with capability ‘Capability(language=‘java’, dependency_manager=‘gradle’, application_framework=None)’ 2021-03-15 16:05:25,927 | Registering workflow ‘JavaMavenWorkflow’ with capability ‘Capability(language=‘java’, dependency_manager=‘maven’, application_framework=None)’ 2021-03-15 16:05:25,928 | Registering workflow ‘DotnetCliPackageBuilder’ with capability ‘Capability(language=‘dotnet’, dependency_manager=‘cli-package’, application_framework=None)’ 2021-03-15 16:05:25,930 | Registering workflow ‘CustomMakeBuilder’ with capability ‘Capability(language=‘provided’, dependency_manager=None, application_framework=None)’ 2021-03-15 16:05:25,930 | Found workflow ‘NodejsNpmBuilder’ to support capabilities ‘Capability(language=‘nodejs’, dependency_manager=‘npm’, application_framework=None)’ 2021-03-15 16:05:25,931 | Running workflow ‘NodejsNpmBuilder’ 2021-03-15 16:05:25,931 | Running NodejsNpmBuilder:NpmPack 2021-03-15 16:05:25,931 | NODEJS packaging file:/Users/matthew/dev/sam-example/templates/src/Function to /var/folders/60/ysxysrqd1zd34cqj963b0g400000gn/T/tmpqvkkcr_q 2021-03-15 16:05:25,931 | executing NPM: [‘npm’, ‘pack’, ‘-q’, ‘file:/Users/matthew/dev/sam-example/templates/src/Function’] 2021-03-15 16:05:26,412 | NodejsNpmBuilder:NpmPack failed Traceback (most recent call last): File “/usr/local/Cellar/aws-sam-cli/1.21.0/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/nodejs_npm/actions.py”, line 59, in execute tarfile_name = self.subprocess_npm.run([“pack”, “-q”, package_path], cwd=self.scratch_dir).splitlines()[-1] File “/usr/local/Cellar/aws-sam-cli/1.21.0/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/nodejs_npm/npm.py”, line 85, in run raise NpmExecutionError(message=err.decode(“utf8”).strip()) aws_lambda_builders.workflows.nodejs_npm.npm.NpmExecutionError: NPM Failed: npm ERR! code ENOLOCAL npm ERR! Could not install from “…/…/…/…/…/…/…/Users/matthew/dev/sam-example/templates/src/Function” as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in: npm ERR! /Users/matthew/.npm/_logs/2021-03-15T23_05_26_391Z-debug.log
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/usr/local/Cellar/aws-sam-cli/1.21.0/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflow.py”, line 269, in run action.execute() File “/usr/local/Cellar/aws-sam-cli/1.21.0/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/nodejs_npm/actions.py”, line 70, in execute raise ActionFailedError(str(ex)) aws_lambda_builders.actions.ActionFailedError: NPM Failed: npm ERR! code ENOLOCAL npm ERR! Could not install from “…/…/…/…/…/…/…/Users/matthew/dev/sam-example/templates/src/Function” as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in: npm ERR! /Users/matthew/.npm/_logs/2021-03-15T23_05_26_391Z-debug.log
Expected result:
success
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Mac
sam --version
: SAM CLI, version 1.21.0- AWS region: us-west-2
Add --debug flag to command you are running
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
I believe that is fixed, thanks for the quick turnaround!
On Mon, Mar 15, 2021 at 11:16 PM _sam @.***> wrote:
I’m experiencing this same issue with sam
1.59.0
.I’ve got a stack template at
deploy/stack.yml
that defines a function with CodeUri property:samconfig.toml
:The function package is at
functions/scale-image/build/scale-image.zip
.