Hi, awesome people :wave: Having a weird issue wi...
# general
b
Hi, awesome people 👋 Having a weird issue with deploying Lambda@Edge functions using
aws.lambda.CallbackFunction
. For some reason, Pulumi started deploying these functions included a big portion of
node_modules
in the package, which deploys a package size of +15.5 MB (which is too big to use as a Lambda Edge. I have tried stripping everything in the function and making sure to prevent any open closures, basically reducing it to
callback: () => {}
. No matter what I do, it keeps including
node_modules
in the lambda package itself. It used to worked perfectly, now I have zero idea what I suddenly did wrong to trigger this. Any ideas how I can debug this, or how I can force-exclude
node_modules
from the package?
e
Do you know what version of the pulumi sdk this used to work with?
b
Ah, you're saying something. I think I just upgraded. Is there a know breaking change regarding this?
e
I don't know of any, and looking at the nodejs repo I can't see anything obvious in history but I'm not the resident nodejs expert 🙂 If you do have a version it worked at that will help narrow it down (and also confirm it is due to an sdk change and not some other dependency changing)
b
I will try this and get back, thanks.
Alright, I tried a bunch of different earlier version. It didn't solve the issue. I also tried destroying the entire stack and setting everything up from scratch. No luck. This is driving me pretty crazy! The lambda bunde definitely includes a
node_modules
with what looks like all NodeJS inbuilts. These are already a part of the execution environments for lambdas, and should not be included. I have no idea why this started to happen. Any pointers? Is there any way I can control how Pulumi is building / treeshaking? (ala. webpack).
Actually, now that I look closer. It seems to be doing this on every single lambda in the entire stack, not just the Lambda@Edge. This definitely doesn't seem right.
Just tried to replicate the same functionality with both Serverless and AWS CDK, and it works perfectly (stripping everything but the necessary code). This seems like a Pulumi bug to me.
e
No luck using old SDK versions?
Ah sorry saw your first comment. Just to check the earlier versions we're earlier SDK versions (i.e.
@pulumi/pulumi
)
b
Unfortunately, no luck with earlier versions, no.
Do you know of any way I can customize the serialization process? That would also help me solve another issue I raised a few days ago: https://pulumi-community.slack.com/archives/C84L4E3N1/p1654756632934759 I see that when I keep variables outside the callback scope, Pulumi actually wraps everything in an extra function scope, and does this funny
with({ variable })
which causing me issues with this.
e
Unfortunately, no luck with earlier versions, no.
Shame that would of made things easier
Do you know of any way I can customize the serialization process?
I don't, it's all black magic to me 😆 I'd suggest raising an issue at our github, can get one of the more "nodejs knowledgeable" team members to have a look.
b
That would be great. I see the "black magic" is actually very well-described here - except, it doesn't do what it says it does here 😅 It exactly doesn't strip the
node_modules
, and it doesn't seem like there's any way to add custom logic to this process 😞 https://www.pulumi.com/docs/intro/concepts/function-serialization/
Alright! I found a (slightly tedious) solution, but it does work. The
lambda.CallbackFunction
takes a
codePathOptions.extraExcludePackages
field, and if I systemically add every single dependency here, it seems to work. My guess is that the node bultins are included in some sub-dependency, and pulumi can't figure out to strip it under nested levels like this. But at least, this works 👌