Skip to content

How to do tree-shaking of aws-sdk? #113

Answered by mrgrain
Kelvijn asked this question in Q&A
Discussion options

You must be logged in to vote

Ah yes, I see. This will be because of this: import * as AWS from 'aws-sdk'

Long story short, esbuild doesn't know what parts of the SDK to "shake". You will have to change how you import aws-sdk. AWS has written a good blog post about this: https://aws.amazon.com/blogs/developer/modular-packages-in-aws-sdk-for-javascript/

E.g. to use S3 you will have to write

import S3 from "aws-sdk/clients/s3";

instead.


Alternatively, because you're creating a Lambda, you can mark aws-sdk as external und fallback to the version that comes pre-installed on Lambda:

new TypeScriptCode("./src/index.tsx", {
  buildOptions: {
    external: ["aws-sdk"],
  },
});

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@Kelvijn
Comment options

@Kelvijn
Comment options

@mrgrain
Comment options

@Kelvijn
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mrgrain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants