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

Allow option to exclude aws-sdk from final bundles #8864

Closed
arackaf opened this issue Feb 3, 2023 · 9 comments
Closed

Allow option to exclude aws-sdk from final bundles #8864

arackaf opened this issue Feb 3, 2023 · 9 comments
Labels
feature / enhancement New feature or request
Milestone

Comments

@arackaf
Copy link

arackaf commented Feb 3, 2023

Describe the problem

AWS Lambda currently (automatically) ships a version of the "aws-sdk" package (NOT the various "@aws-sdk/dynamo|lambda|etc|etc" packages).

You still have the option to bundle, and ship your own version of the sdk, if you need a very specific version, but otherwise you can exclude it, and save a TON of bundle size in your lambda.

It would be great if SvelteKit were to expose an exclude or external option for that purpose (which, presumably, esbuild would just hook into).

The difference can be substantial. I just removed a single usage of aws-sdk for the DynamoClient, and replaced it with @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb and the deployed function size dropped by 1.86MB (yes, really).

Describe the proposed solution

The Vercel adapter already has an external config property, but it's only for edge functions. Could we open it up for Lambda deploys, too? aws-sdk is the only use case I can think of for it, but there might be others—plus, aws might in the future start shipping the v3 @aws-sdk/xyz packages, so this would be useful for that, too.

Alternatives considered

Not that I can think of.

Importance

would make my life easier

Additional Information

No response

@arackaf
Copy link
Author

arackaf commented Feb 3, 2023

One fun addendum: Node 18 Lambda's actually do include the v3 sdk, but not the v2 sdk. So this actually isn't limited to just one dependency to be excluded.

aws/aws-lambda-base-images#47 (comment)

@Rich-Harris Rich-Harris added the feature / enhancement New feature or request label Feb 3, 2023
@Rich-Harris Rich-Harris added this to the later milestone Feb 3, 2023
@thdxr
Copy link

thdxr commented Feb 9, 2023

@arackaf just an FYI you do NOT want to use the provided v3 in the node 18 lambda due to a serious performance cost

v3 is made up of many files and the environment provided ones are not bundled, so node has to traverse and read them all - we're talking 100s of ms of additional cold start

my current recommendation is to continue to bundle v3 (which adds to bundle size but still faster than using the environment one) or sticking with v2 and node 16 and ensuring your imports are of this format
import S3 from "aws-sdk/clients/s3"

@arackaf
Copy link
Author

arackaf commented Feb 9, 2023

@thdxr ohh - that's good to know, thank you! If this ever lands I'll be sure to profile both

@benmccann
Copy link
Member

I'm not really sure what the ask is here. It seems like something that should be a feature request for whatever AWS adapter you're using like https://github.com/jill64/sveltekit-adapter-aws

@arackaf
Copy link
Author

arackaf commented Oct 7, 2023

@benmccann The ask is for SvelteKit to provide an "exclude" (or similar) option to exclude certain libraries (like aws-sdk) from the final js bundle that's uploaded to aws. This would reduce bundle size, and leave the lambda function to use the v3 sdk they come pre-loaded with.

Whether such an option would be desirable / performant, per @thdxr's comment, is another matter.

@benmccann
Copy link
Member

The options that control the build are located in the adapters and in Vite. E.g. in Vite there's https://vitejs.dev/config/build-options.html#build-rollupoptions. And adapter-vercel has an external option, which does this: https://kit.svelte.dev/docs/adapter-vercel#deployment-configuration. But it's unclear to me which adapter you're using and so I don't know if there's anything to be done in this repo or if you need to file this issue in the repo for a community adapter

@arackaf
Copy link
Author

arackaf commented Oct 7, 2023

Ohhh interesting - feel free to close this, then, if that's the case!

Thanks for the info!

@benmccann
Copy link
Member

No problem! Sorry this sat without an answer for you all this time!

@arackaf
Copy link
Author

arackaf commented Oct 7, 2023

Turns out it's probably a bad idea anyway, like Dax said :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants