@aws-cdk/aws-lambda-nodejs doesn't build functions with native modules
See original GitHub issueI’m trying to get a lambda set up with @aws-cdk/aws-lambda-nodejs.
I applied the change mentioned in #6274, and now I have a build error:
Error: Failed to build file at [my lambda function]: Error: 🚨 [project path]/node_modules/pg/lib/native/client.js:11:21: Cannot resolve dependency ‘pg-native’
Reproduction Steps
Use "pg": "7.18.1"
, then in the source of the lambda:
import * as pg from 'pg';
Error Log
Error: Failed to build file at [my lambda function]: Error: 🚨 [project path]/node_modules/pg/lib/native/client.js:11:21: Cannot resolve dependency ‘pg-native’
Environment
- CLI Version : 1.24.0
- Framework Version: 1.24.0
- OS : OS X 10.15.3
- Language : Typescript
Other
I’m familiar with how to work around this error in Webpack, but given that Parcel is a zero config tool, I’m not sure what to do about this error.
I think connecting to RDS databases from Node Lambdas will be a common use case, so this should be supported out of the box if possible, or at least have a documented solution.
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:19 (8 by maintainers)
Top GitHub Comments
FWIW, let me share my workaround of this issue for future reference. I didn’t intend to use
pg-native
, so set it to theexternalModules
settings as follows.@jogold I think we should add support for building the function inside a Lambda docker image (like/with “sam build”). What do you think?