I have a lambda where I import ‘aws-xray-sdk’ but ...
# aws
I have a lambda where I import ‘aws-xray-sdk’ but the dependency does not seem to be uploaded to AWS as the lambda throws “errorType”“Runtime.ImportModuleError”,“errorMessage”“Error: Cannot find module ‘aws-xray-sdk’… Shouldn’t Pulumi automatically handle this? I run npm i aws-xray-sdk before pulumi up ofc.
that's not up to pulumi, is the dependency on your package.json? make sure it's there, npm install as 'prod' dependency not a dev one
It’s in my package.json yes under dependencies
then the other thing I can think of is that pulumi is not deploying your dependencies. look if node_modules is in aws
in the lambda file system explorer
it's also a bit of a weird library
try with
Copy code
import AWSXRay from 'aws-xray-sdk-core';
Using ‘aws-xray-sdk-code’ results in the same problem. I can only see my __index.js in the Code source explorer, unless you are referring to another part of the AWS console
I am defining the lambda from a file, do I have to add the dependencies here explicitly?
Copy code
const fn = new aws.lambda.Function('InfraLambda', {
  code: new pulumi.asset.AssetArchive({
    '__index.js': new pulumi.asset.FileAsset('./handler.js'),
  handler: '__index.handler',
  runtime: aws.lambda.NodeJS12dXRuntime,
  role: role.arn,
  tracingConfig: {
    mode: 'Active', // Enable X-ray
yep you need to also push over the node_modules folder, so that's another asset. or use webpack to pack only your 'prod' dependencies and then declare the result of the build as an asset
Alright thanks
I am using a library that copies node_modules over to /build folder and I am using that as asset. but I am using typescript so I need to transpile over the files
I’ll check it out