hi everyone! im trying to debug a Runtime.ImportMo...
# help
j
hi everyone! im trying to debug a Runtime.ImportModuleError error and ive hit a wall 😞 with the local development workflow, everything works fine 👍 once i build and deploy to prod, i can see in the cloudwatch logs that the lambda function does not start properly due to an
Runtime.ImportModuleError
error. i have a simple sqs queue with a lambda fn attached as a consumer. ive added
mysql2
and
knex
as layers. the specific error is that the module
knex
cannot be found during runtime. any advice on how to debug this issue? thanks in advance!
slack search is your friend 😉 https://serverless-stack.slack.com/archives/C01JG3B20RY/p1623958746417900
s
@John Kor @Gabriel Gordon-Hall you shouldn’t need a webpack config at all. I use knex in my SST project, and this works for me: (somewhere at the entry of your stack)
Copy code
app.setDefaultFunctionProps(stack => ({
    // ...
    bundle: {
      // sharp is a binary, and we have it in a Lambda layer, so exclude it
      externalModules: [
        'sharp',
        'knex',
        '@aws-sdk/signature-v4-crt',
      ],
      loader: {
        '.node': 'binary',
      },
    },
    layers: [
      lambda.LayerVersion.fromLayerVersionArn(
        stack,
        'KnexLayer',
        process.env.KNEX_LAYER_ARN
      ),
    ],
j
@Sam Hulick thanks! my takeaway from the message i shared above was the
nodeModules
option under
bundle
🙂 so similar to the snippet you shared