Have you ever wondered how easy it can be to deploy and host an API? Scalable, stable, a piece of cake to deploy and costs almost nothing. The goal...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks for this tutorial. Sadly after running sls deploy, when I go to the production URL ending with / song, I get a 500 error. In Cloudwatch the error is: Cannot find module './dist/lambda.js'". Any idea on how to fix it? Cheers
It might be because
nest-cli.jsonconfig file only expectsmain.tsto get compiled tomain.js. So, one should specifylambda.tsas well or instead writehanlder()function inmain.ts.I tried both options, but both results were Cannot find module either ./dist/lambda.js or ./dist/main.js
For the first: I added the entryFile to my out-of-the-box best v.10.0.0 different looking nest-cli.json :
For the second option, I added the handler to the main.ts
and updated the serverless.yml from
to
my tsconfig.json in case is relevant is:
Thanks for the reply! I guess I have to try the guide my own to check the reason solid clear. 'll get back with an update!
I'm back! :)
I've tried the whole thing with my NestJS + serverless.yaml setup and everything works good enough. However, I'm using Yandex Serverless Functions instead of AWS Lambda, but I tend to think this part is irrelevant to the issue.
Here're some of the info:
9.5.0A note here! In the
packagerule I'm making sure that the dist directory with mymain.tsfile is compiled and other files that I do need.I'm not entirely sure what the exact reason behind your issue, but I guess you could try to debug if the main.ts/lambda.ts is being compiled into main.js/lambda.js and, furthermore, being packaged by Serverless Framework (in a .zip archive). I hope my configs will be of some help
Thanks, great article.
Earlier I was able to run and test nest-api locally by running npm run start:dev.
But running this cmd with serverless-express , its not running on locally with watch mode.
How can I do this , so that both npm run start:dev gives me local api to play around.
Hi, thanks for reading and for your comment! I believe you should be able to run it just as before, so npm run start:dev should work. The serverless-express wrapper is only ran when it's deployed via serverless.
To emulate Lambda locally serverless-offline plugin can be used, however I am not sure if it supports the watch mode equivalent.
In any case let me know if you find any specifics, or if I misunderstood your question.
Thanks, I was following another tut also, got confused. In another tut it modify the main.ts rather than creating a new file lambda.ts.
Cool 😉
Hi, thanks for the article!
I was just wondering if you've run into the issue where DTO decorators for
class-transformerandclass-validatorwork locally in testing, but do not work once deployed to AWS ApiGateway/Lambda? Locally, the request will just be outright reject and it won't even attempt to process the request, when deployed it will attempt to process a request with a malformed DTO.I am using the exact same tooling as you, and very similar set up.
Thanks!
Hi, thanks for the comment. If I understand your question correctly, I'd say that this is expected behavior. Lambda should proxy every request, it's up to your Nest app to handle validation responses, and just proxy them back to API Gateway.
If I misunderstood then feel free to provide more details about your issue and I'll try to pitch in. 👍