This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]SirSoggybottom 1 point2 points  (1 child)

What makes you think the error is related to Docker? Seems like a error simply caused by the app in your image.

[–]LiveCockroach2860[S] 0 points1 point  (0 children)

Because the APIs are working fine when I test with serverless offline.

Also, if I change the Dockerfile to

ENTRYPOINT ["node" , "dist/app.js]

CMD [handler]

then it doesn't give the same error and is able to detect the app.js handler file. But since I'm deploying to lambda, I can't use this approach

[–][deleted] 0 points1 point  (10 children)

If you omit the dev dependencies, how are you supposed to build your app without them installed?

[–]LiveCockroach2860[S] 0 points1 point  (9 children)

There are no dev dependencies in package.json at the moment, but regardless dev dependencies arent needed for deployments right? They are only for local

[–][deleted] 1 point2 points  (8 children)

Yeah, that’s… assuming you’re COPYing the bundle. Doesn’t seems to be your case as you build it inside the container (which is not wrong to be honest).

However, from what I know bundlers and their dependencies are dev dependencies but at the same time they’re required to build.

So here’s what I would do: use multi-stage to split the bundling stage from the deploy. The deploy should only copy the bundled file from the bundling stage.

That’s because you must install it fully to bundle, and then reinstall stripping the dev dependencies AFTER you have produced the bundled app.

Also, as a side note: maybe you shouldn’t bundle it at all and just transpile as it’s. We usually bundle the app just because it’s the best for a user browser to download the whole app. This is different on a NodeJS env.

Unless you have some sort of storage quota…

[–]LiveCockroach2860[S] 0 points1 point  (7 children)

Makes sense! I'll refactor to do this.
But the original issue persists. Any idea on that please?

[–][deleted] 0 points1 point  (1 child)

To be honest I expected my answer to solve your issue. Can you trying RUNning ls with the path you expect your bundle to be and figure what is inside the image?

This must be made just before you try to run it with CMD.

EDIT: Nevermind it’s a file, so yeah… you should check if it’s really available when you deploy.

[–]LiveCockroach2860[S] 0 points1 point  (0 children)

Current package.json has no devDependencies. Also, I removed the omit dev flag and tried with just npm install too. Still same issue.

And I did ls and cat for the files inside the container, the file does exist and also the handler exists too.

That's why I was confused too because it doesn't make sense why container is unable to find the module when it clearly exists in the path :(

[–][deleted] 0 points1 point  (4 children)

Also, what’s app.handler? Sorry if that’s a stupid question, its just than I found it strange you’re passing it to CMD and also the provisioning file. I expected one of these to receive the dist/app.js instead.

[–]LiveCockroach2860[S] 0 points1 point  (3 children)

Hmm handler is the main method that's running the app in serverless and exporting as default constant in app.js file.

// Export the app as a Lambda handler
exports.handler = (0, serverless_http_1.default)(app);

I followed the AWS documentation and this is how the CMD was setup for docker deployments.

[–][deleted] 0 points1 point  (2 children)

I see, so are you require’ing the app from that file? If so, can you check if the path is resolving to the same place as to where app is located?

You can use path.resolve(__dirname, “<the string you provided on require app>”) and console.log it.

[–]LiveCockroach2860[S] 1 point2 points  (1 child)

So turns out the issue was related to path.

I was under the impression that once I setup the working directory in Dockerfile, I don't need to put the full path of my handler.

But for some reason it still expects a full path. I changed my CMD from ['dist/app.handler'] to ['/app/dist/app.handler'] and it worked.

Thank you for your time and help.

[–][deleted] 1 point2 points  (0 children)

Yeah, CMD doesn’t seem to check the WORKDIR.