Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAM build doesn't install local file dependency #3854

Closed
AlDawoode opened this issue May 5, 2022 · 8 comments
Closed

SAM build doesn't install local file dependency #3854

AlDawoode opened this issue May 5, 2022 · 8 comments
Labels
area/build sam build command

Comments

@AlDawoode
Copy link

Description:

I have a SAM template that create a lambda function (Node js project).
As i understand when i run the command "SAM build", SAM read the SAM-template and start to copy all files needed to the folder called ".aws-sam" and it will run npm install at the end...

The issue happen when i declare a local file dependency in my package.json.
SAM not able to install the local file dependency, because the file path for the local dependency is not right anymore (because SAM copied the files to another location (to .aws-sam folder)

In my Lambda function folder there is a package.json file that contain local file dependencies :
{
"name": "import-temp-tables-to-db",
"version": "1.0.0",
"description": "",
"main": "none.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "UNLICENSED",
"dependencies": {
"shared": "file:../../shared",
"api-utilities": "file:../../../shared/api-utilities",
"debug": "^4.3.3"
}
}

If i don't use sam build at all, and instead use npm install, then the local file dependencies appear under node_module (because the path is right).

  1. OS: windows or ubuntu
  2. sam --version: SAM CLI, version 1.41.0
@jfuss
Copy link
Contributor

jfuss commented May 5, 2022

@AlDawoode Thanks for the issue. This is a current limitation in how the npm builder works. We have an open issue on this in our AWS Lambda Builders module/repo: aws/aws-lambda-builders#222. Here is the design the describes the implementation of the builder: https://github.com/aws/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/nodejs_npm/DESIGN.md

The challenge is two fold:

  1. We use npm pack but never move over the local dependencies.
  2. With local files, unless we change how we build in a container this process will break. We need to get the files into the container in order for sam build -u to work.

The way around this is to use the Makefile builder instead, which allows you to do what you need to do.

@jfuss jfuss added the area/build sam build command label May 5, 2022
@mndeveci
Copy link
Contributor

Resolving this issue since there is already one in Lambda Builders repository: aws/aws-lambda-builders#222

Please feel free to comment on that issue.

@AlDawoode
Copy link
Author

@jfuss @mndeveci
Thank you for your effort

@AdrKacz
Copy link

AdrKacz commented Feb 24, 2023

Any update, it is still not working

@AlDawoode
Copy link
Author

AlDawoode commented Mar 8, 2023

Yes it's still not working. the workaround was made by my team is to use esbuild to bundle all dependencies.
That solved the SAM issue.

@alphonse92
Copy link

It does not works due the symlink natures. By default , local dependencies are a symlink, so when SAM performs the build it copy and paste the dependencies on the dep folder without updating the local dep symlink.

image

@EduRomoGO
Copy link

EduRomoGO commented Aug 24, 2023

I'm programmatically copying my package.json file to the dependencies folder before running the sam local invocation. In fact in my case I have to copy the file inside nodejs folder inside dependencies folder.

echo
echo Copying package.json to dependencies folder
cp -v package.json ./dependencies/nodejs

echo
echo Installing dependencies
cd dependencies
cd nodejs
npm i

cd ..
cd ..
echo
echo "Invoking function ${FUNCTION_NAME} with event ${EVENT_NAME}"

sam local invoke ${FUNCTION_NAME} --event src/events/${EVENT_NAME}.json --profile DEV --env-vars .env.json --region eu-west-1 --template template-personal.yaml

@mndeveci
Copy link
Contributor

mndeveci commented Sep 5, 2023

We've been working on building in source feature, which should resolve local dependencies. See: #4571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command
Projects
None yet
Development

No branches or pull requests

6 participants