https://pulumi.com logo
Title
m

microscopic-florist-22719

06/23/2018, 5:41 PM
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

big-soccer-75859

06/23/2018, 11:30 PM
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

microscopic-florist-22719

06/24/2018, 2:31 AM
We should pick up your imported modules automatically... @white-balloon-205 may have more insight than I here.
w

white-balloon-205

06/24/2018, 4:48 AM
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

big-soccer-75859

06/24/2018, 12:10 PM
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

white-balloon-205

06/24/2018, 2:11 PM
Ahh - okay - that sounds like a bug. Opened https://github.com/pulumi/pulumi/issues/1567.
b

big-soccer-75859

06/24/2018, 2:14 PM
Thanks @white-balloon-205!!