Amplify-cli: Excluding "devDependencies" in Lambda Function's built version

Created on 11 Dec 2019  路  4Comments  路  Source: aws-amplify/amplify-cli

Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum

Which Category is your question related to?

amplify push command

Amplify CLI Version

4.5.0

What AWS Services are you utilizing?

AWS Lambda Function, AWS Lambda Layer

Provide additional details e.g. code snippets

I'm using AWS Lambda Layer in my projects and I'm handling the deployment part manually and only include it in the Lambda CloudFormation file under the "Layers" section and it works fine. However, because I moved my dependencies to my layer, I have also moved them to "devDependencies" in Lambda's package.json. Why? Because I have tests inside the src folder of my lambda functions and in order to run those tests I need my packages to be around.

The problem is that I noticed my lambda size is still too big and when I checked, amplify is installing my "devDependencies" and it's basically doubling the total size because of the layer I have.
Finally, my question:
* isn't amplify supposed to install npm packages with --production flag? If not, how I can set it to do so?*

I'd really appreciate any input or thoughts.

_P.S. I checked and same thing is happening in Amplify Console Build and it makes sense because it's using the same command amplify push --simple_

functions question

Most helpful comment

One workaround could be to create an additional package.json in the root folder of your function (above /src) which only holds your dev dependencies and also to add your test files to the root folder, as the deployment package is built upon the /src folder

All 4 comments

Just to give you an update, I've also taken a look into the amplify-function-plugin and tried to manipulate "amplify:build" & "amplify:push" in my own function's script to create a production build, but no success in that. I know these parts are pretty new, but some documentation would be really appreciated for these scripts and how to use them.
The only part of document that I found related to this topic was in aws-amplify website regarding the "amplify:generateReport".
Anyway, if you guys think I can contribute in any way, just let me know, I'd be happy to work on a fix for this problem.

One workaround could be to create an additional package.json in the root folder of your function (above /src) which only holds your dev dependencies and also to add your test files to the root folder, as the deployment package is built upon the /src folder

One workaround could be to create an additional package.json in the root folder of your function (above /src) which only holds your dev dependencies and also to add your test files to the root folder, as the deployment package is built upon the /src folder

Hey @foxfl,
Thank you for your comment. It seems like a good solution to me. I'll try it and post the result in this issue.

One workaround could be to create an additional package.json in the root folder of your function (above /src) which only holds your dev dependencies and also to add your test files to the root folder, as the deployment package is built upon the /src folder

Worked like a charm for me. I'm gonna close this issue. Thanks again @foxfl

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kangks picture kangks  路  3Comments

nicksmithr picture nicksmithr  路  3Comments

kstro21 picture kstro21  路  3Comments

davo301 picture davo301  路  3Comments

ReidWeb picture ReidWeb  路  3Comments