question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sam build disregards base-dir in 1.21.0

See original GitHub issue

Description:

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)

  1. OS: Mac
  2. sam --version: SAM CLI, version 1.21.0
  3. AWS region: us-west-2

Add --debug flag to command you are running

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mbradburncommented, Mar 16, 2021

I believe that is fixed, thanks for the quick turnaround!

On Mon, Mar 15, 2021 at 11:16 PM _sam @.***> wrote:

should be resolved in version 1.21.1, thank you for reporting this issue!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-sam-cli/issues/2717#issuecomment-799984691, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFIKHYNPDX5QYYHMPT7IOJ3TD3ZUBANCNFSM4ZHNSFKQ .

0reactions
speciouscommented, Oct 13, 2022

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:

CodeUri: functions/scale-image/build/scale-image.zip

samconfig.toml:

version = 0.1
[default.build.parameters]
base_dir = "."
template = "deploy/stack.yml"

# ...

The function package is at functions/scale-image/build/scale-image.zip.

$ sam deploy 
File with same data already exists at littermap-backend/dd7cb1af042d37964aa6999b32e5f1c1, skipping upload
File with same data already exists at littermap-backend/c2a4e1b593c93f309e07d8078ec2281c, skipping upload
Error: Unable to upload artifact ../../deploy/functions/scale-image/build/scale-image.zip referenced by CodeUri parameter of Sc
aleImageFunction resource.
Parameter CodeUri of resource ScaleImageFunction refers to a file or folder that does not exist /home/specious/cc/littermap-aws
/deploy/functions/scale-image/build/scale-image.zip

$ sam --version
SAM CLI, version 1.59.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

sam build disregards base-dir in 1.21.0 issue - PythonTechWorld
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 ...
Read more >
sam build - AWS Serverless Application Model
Build an AWS SAM application using the sam build command from the AWS SAM CLI. ... -s , --base-dir DIRECTORY, Resolves relative paths...
Read more >
Build failed - Error: PythonPipBuilder:ResolveDependencies ...
I solved this using sam build --use-container , however this works only when template.yml file is present. Using the graphical form does not ......
Read more >
aws-sam-cli Changelog - pyup.io
fix: Fix `--docker-volume-basedir` being ignored for sam local by lucashuy in ... fix: --base-dir is disregarded in sam build (#2718) ... 1.21.0. Changes:...
Read more >
circleci/aws-sam-serverless@4.0.0
The sam build command iterates through the functions in your application, looks for a manifest file (such as requirements.txt) that contains the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found