Replies: 6 comments
-
What about adding a flag to sam build to give the users possibility to choose? |
Beta Was this translation helpful? Give feedback.
-
First, I'd echo @roman-boiko to ask for a flag or some type of escape hatch to force behavior one way or another as a user. Obviously, the Second, assuming we have an escape hatch, this becomes a question of "what is the correct/best default"? TLDR: default to assuming you're building for production. To answer this question more fully, I would lean into the principal of least surprise. That is, what would someone who doesn't know about this new behavior expect to happen? And maybe more importantly, what would be the impact of the unexpected happening? Especially if they have infrastructure/processes already set up and blindly upgrade. I think its much less risky to build with the Two major reasons are security and performance (which, in a Serverless world also equates to cost).
In my opinion, having a secure and performant production environment greatly outweighs the slight inconvenience of having to add an additional flag, set a local environment variable, or re-run an install command when building locally. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback @roman-boiko @brnkrygs 🙏 , this is very helpful! |
Beta Was this translation helpful? Give feedback.
-
A better solution is to extend the existing esbuild functionality, so even regular NodeJS functions take advantage of the tree shaking? Not installing dev dependencies will result in a smaller bundle, but it will still be nowhere near as small as a tree shaked file. |
Beta Was this translation helpful? Give feedback.
-
Agree the --production flag is probably best as a configurable parameter. |
Beta Was this translation helpful? Give feedback.
-
TL;DR building in the CodeUri would be great, I agree that prod-only is a good default, would also like an option to disable When working with typescript and esbuild, it would be helpful to have some kind of control over whether an In any case, building in the source directory would be very helpful. We have a similar pattern as the linked issue regarding local dependencies. We have folders which get imported across several lambdas (they aren't declared as dependencies in any package.json file though, esbuild just brings them in). We have to set the CodeUri to |
Beta Was this translation helpful? Give feedback.
-
When building certain runtimes (Java, NodeJS, Python, Ruby, provided/custom), SAM CLI copies the source code and builds in another directory. We're working on adding an option to allow building in the source code directory instead. This should enable support for local dependencies (see example issue here) and potentially bring build speed improvements.
For NodeJS (without esbuild), SAM CLI currently copies the source code and installs using npm's
--production
flag, so that dev dependencies don't end up being uploaded. This doesn't affect thenode_modules
in the source code, so users can continue to use their dev dependencies after building.However, if we want to build in the source directory, we need to choose between
--production
flag). This means dev dependencies won't be uploaded, but it also means that in order to use dev dependencies users will need to install them themselves after everysam build
.--production
flag). This means users can keep their dev dependencies but these will also be uploaded unless users prune them themselves before packaging/deploying.We're looking to get feedback from NodeJS users into which option they'd prefer (or if they have other ideas/suggestions).
Beta Was this translation helpful? Give feedback.
All reactions