I am excluding aws-sdk in my webpack bundle for Lambda

When webpacking for lambda, I am removing aws-sdk completely from the webpack bundle since lambda has it built-in. However, it seems to be throwing errors. Is there a way to specify that it needs to use the lambda's aws-sdk? If I do node index.js (the webpack output file), I get an error saying that aws-sdk doesn't exist. Since lambda has aws-sdk built in, I assumed if I upload the zipped file to lambda, it would understand it. However, I'm getting an error in Lambda CloudWatch console saying Unable to import module 'index'

1 answer

  • answered 2018-11-19 15:53 gatsbyz

    You want to use webpack's Externals, rather than ignore.

    Try adding this to your webpack config:

     externals: {
        'aws-sdk': 'aws-sdk'

    That will keep aws-sdk from being bundled into index.js, and will instead use lambda-provided aws-sdk instead.