If you’re not already doing so, you’ll need to imp...
# general
m
If you’re not already doing so, you’ll need to import the module inside the body of the handler. In typescript, this is the
await import
syntax.
b
Yep that seemed to work
or maybe not
Is there anything special I need to do to get node modules packaged in with the function
m
We should pick up your imported modules automatically... @white-balloon-205 may have more insight than I here.
w
Yes - any packages you depend on in code that gets serialized into a Lambda should be included in
node_modules
automatically. If you are not seeing that - would be great if you could open an issue with details of your example so that we can investigate. Note that if packages are not getting included, you can explicitly include them using e.g.
pulumi config set cloud-aws:functionIncludePackages express
. See https://github.com/pulumi/pulumi-cloud/blob/master/aws/config/index.ts#L42 for a few details on this config setting.
b
Thanks guys, I'll give it a go and report back
I think I worked out whats happening. If I put this within my handler function
const jwt = await import('jsonwebtoken');
it actually packages the
@types/jsonwebtoken
module rather than the actual
jsonwebtoken
module. Note that
@types/jsonwebtoken
is in my devDependencies
So removing
@types/jsonwebtoken
and changing the line to
const jwt = require('jsonwebtoken');
fixed the build but obviously the library becomes an
any
which is a bit annoying but I can deal with it.
w
Ahh - okay - that sounds like a bug. Opened https://github.com/pulumi/pulumi/issues/1567.
b
Thanks @white-balloon-205!!