Hey guys! There is a major pain I’m trying to thi...
# typescript
Hey guys! There is a major pain I’m trying to think how to handle. I have a layer that injects some common nodejs modules. This layer is attached to some lambda I have. Now when I write my lambda code that relies on that package, I also import the package at the top of the file. What happens then is that Pulumi attempts to bundle that package into my lambda code, even tho the only reason I have it installed is so I can create a layer with this module. How can we tell Pulumi not to bundle this package? Also, Pulumi does not respect tree-shaking and bundles the entire package even if I’m using a subset of the package. Is my only option here is to pipe my code through a more “intelligent” such as webpack to do the tree-shaking for me?
you’re using the CallbackFunction to provide your lambda code? If you want more fine-grained control over your lambda you can bundle it using the
arg https://www.pulumi.com/docs/reference/pkg/aws/lambda/function/#code_nodejs
Here’s an example that uses a separately written lambda rather than a serialized inline function: https://github.com/pulumi/examples/blob/master/aws-ts-apigatewayv2-http-api/index.ts#L42-L44