Moralis.start error when running on AWS Batch

Here there, I was trying to run a batch job fetching some blockchain data using Moralis APIs. The job calls Moralis API by calling (node.js)

Moralis.start({
    serverUrl,
    appId,
  });

first. I’ve logged serverUrl and appId and double-checked that there are correct. Everything works fine when running locally or within a docker container pushed by myself on AWS ECR.

However, when trying to run the exact same script in AWS Batch using the same docker image, I got the following error in AWS logs:

(node:1) UnhandledPromiseRejectionWarning: Error: Received an error with invalid JSON from Parse: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /serve/functions/getPluginSpecs</pre>
</body>
</html>
    at handleError (/app/node_modules/moralis/lib/node/RESTController.js:426:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Function.initPlugins (/app/node_modules/moralis/lib/node/MoralisWeb3.js:436:40)
    at async Function.start (/app/node_modules/moralis/lib/node/Parse.js:146:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1) UnhandledPromiseRejectionWarning: Error: Received an error with invalid JSON from Parse: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /serve/functions/getPluginSpecs</pre>
</body>
</html>
    at handleError (/app/node_modules/moralis/lib/node/RESTController.js:426:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Function.initPlugins (/app/node_modules/moralis/lib/node/MoralisWeb3.js:436:40)
    at async Function.start (/app/node_modules/moralis/lib/node/Parse.js:146:7)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:1) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (/app/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/app/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:293:11)
    at IncomingMessage.emit (events.js:412:35)
    at IncomingMessage.emit (domain.js:475:12)
    at endReadableNT (internal/streams/readable.js:1334:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)

I am not sure what might be the reason for these errors. It would be great if I can get any help on this. Thanks!

it looks like this would be an error message, but I don’t know why

Thanks @cryptokid, yea, it is very hard to know what exactly caused this. Having no clue about how to fix it.

Might be a question for AWS Support. I had issues running an API with Lambda (only when deployed, not locally) with the same exact code, something due to differences in code execution.

Is that .start the only code? If there’s more take out parts and see if you can narrow it down.

Yes, .start is the only code in the script. Could this be some permission or networking access issue?

What were your issues with Lambda and what were your solutions? Maybe I can give it a try.

I couldn’t find a solution for it - it was basically timing out and not returning anything so I ended up switching back to just Express. With the POST error that could be a permission issue. Contacting them would be your best bet.

The unhandledRejection event is emitted whenever a promise rejection is not handled. “Rejection” is the canonical term for a promise reporting an error. As defined in ES6, a promise is a state machine representation of an asynchronous operation and can be in one of 3 states: “pending”, “fulfilled”, or “rejected”. Somebody decided that JavaScript programmers couldn’t be trusted with managing promise rejections properly and changed the HTML spec to require browsers to throw “unhandled promise rejection” errors if a rejected promise has no rejection handlers added before code returns to the event loop. The error usually happens in async await functions, and there’s an easy fix.

const functionName = async (arguments) => {
  try {
  // Your code here
  } catch (error) {
  // Handle rejection here
  }
};