Hi there, congratulations on your work done on SST...
# help
s
Hi there, congratulations on your work done on SST! It seems very nice, so I'm giving it a try, so far I've been using Serverless Framework (SF) with plugin
serverless-webpack
to get small-sized lambdas and when I migrated a simple project over SST, I found that with SST I get bigger sized lambdas.
For example lambda
createUser
with SF outputs 98kB, while with SST 494kB.
Is there any configuration I can tweak on SST to lower the lambda size?
a
Yes you can. SST uses
esbuild
behind the scenes (there's also a SF plugin for that) and it's much faster than webpack. You can use the
bundle
property in function and even as a default globally, here's the API for it https://docs.serverless-stack.com/constructs/Function#functionbundlenodejsprops You can also use esbuild plugins (e.g. for decorators)
And just as a note, when I compared esbuild vs webpack in serverless framework I got better results in terms of lambda size with esbuild 🤷‍♂️
s
Using
Copy code
new Function(stack, 'createUser', {
    handler: 'modules/users/useCases/createUser/index.handler',
    bundle: {
      format: "esm",
      minify: true
    }
  });
I get a smaller size (406.3 kB) but it still falls short of SF's 98kB, could you share your
bundle
settings?
a
I don't have anything different, but it depends a lot on the code. Were you excluding
aws-sdk
with webpack? Maybe it's getting bundled
r
Also look out for re-exported modules via an index.ts - let me find the thread this was discussed in
t
I need to do a video on debugging this
Copy code
esbuild --minify --bundle --format=esm --target=esnext --platform=node ./backend/functions/workspace/events.ts --outfile=output.js --analyze=verbose
here's a command you can run to see what's getting packaged in there