-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't deploy GraphQL to Lambda with CDK #7749
Comments
Add |
So I did try doing this. The one that i was unsure of was the last error which was a bit different:
I went ahead and added it to the lazyImports array to get this as my config: module.exports = (options, webpack) => {
const lazyImports = [
'@nestjs/microservices/microservices-module',
'@nestjs/websockets/socket-module',
'@apollo/federation',
'@apollo/gateway',
'ts-morph',
'class-transformer/storage',
'@apollo/federation/dist/directives',
'./fsevents.node'
];
return {
...options,
externals: [],
plugins: [
...options.plugins,
new webpack.IgnorePlugin({
checkResource(resource) {
if (lazyImports.includes(resource)) {
try {
require.resolve(resource);
} catch (err) {
return true;
}
}
return false;
},
}),
],
};
}; I'm now getting a weird error from Lambda claiming my main.handler does not exist or was not exported, even though i verified that it does exist in the bundled file. I guess my main question at this point is, even if I happen to get this working, is this even maintainable/practical? And is there any better way that you know of? |
If you want to bundle your code, this is the best way to accomplish it.
Did you set the |
I hadn't noticed that section, whoops. I added that configuration and added the fsevents to the externals instead to get: module.exports = (options, webpack) => {
const lazyImports = [
'@nestjs/microservices/microservices-module',
'@nestjs/websockets/socket-module',
'@apollo/federation',
'@apollo/gateway',
'ts-morph',
'class-transformer/storage',
'@apollo/federation/dist/directives'
];
return {
...options,
externals: {
fsevents: "require('fsevents')"
},
plugins: [
...options.plugins,
new webpack.IgnorePlugin({
checkResource(resource) {
if (lazyImports.includes(resource)) {
try {
require.resolve(resource);
} catch (err) {
return true;
}
}
return false;
},
}),
],
output: {
libraryTarget: 'commonjs2'
}
};
}; This builds and Lambda is able to run it, but it immediately fails after running NestFactory and loading the modules, saying:
Running npm ls graphql gives me
So it doesn't appear to be installed multiple times. And I ran |
Check out these threads: Please, use our Discord channel (support) for further questions. We are using GitHub to track bugs, feature requests, and potential improvements. |
Bug Report
Hi there, my organization uses CDK to deploy resources and I'm close to convincing my teams to move most of our service stacks to using NestJS as we rebuild our entire backend.I am trying to build a proof-of-concept using CDK to deploy a NestJS GraphQL API to AWS Lambda behind API Gateway. In order to fit with the constraints of Lambda's code size, my understanding is we'd need to use a bundler of some sort to do tree-shaking and minify the code. However, it seems like bundling is discouraged based on the final response in this thread: #1706. So I'm wondering if you have any guidance on how to deploy to Lambda. It seems Serverless Framework does... something... with their plugins to make it work, but I can't use Serverless Framework unfortunately.
Current behavior
Using the Webpack configuration provided in https://docs.nestjs.com/faq/serverless and running
nest build --webpack
with a basic GraphQL server yields:Trying to manually install these dependencies causes it to need more dependencies so surely that's not the solution.
Input Code
Copied Webpack config from NestJS website:
Copied entry file from NestJS website:
Expected behavior
I'm able to build the package with Webpack or package the code up in some other way to be able to deploy a GraphQL API to Lambda with CDK (rather than Serverless Framework).
Environment
The text was updated successfully, but these errors were encountered: