Docker running amazon/aws-lambda-nodejs JSON errors


Running into this error within Docker lambda logs

...ERROR Invoke Error  {"errorType":"SyntaxError",
"errorMessage":"Unexpected end of JSON input","stack":
["SyntaxError: Unexpected end of JSON input"," at JSON.parse (<anonymous>)","
 at Runtime.handleOnce (/var/runtime/Runtime.js:67:14)"]}

When using a fetch:

await fetch(url, requestOptions)
    .then(function (response) {
        if (response.ok) {
           return response.json();
        return false;

Called via this simplified request for testing:

requestOptions = {
   method: 'POST'
   cache: 'no-cache',
   headers: {
      'Content-Type': 'application/json'
   redirect: 'follow',
   referrerPolicy: 'no-referrer',
   body: JSON.stringify({ "message": "Hello World!" })

and respective URLs:

http://localhost:9002/2015-03-31/functions/function/invocations   // runs into a CORS issue on the frontend and produces the aforementioned log


http://localhost:8080/api // 404 not found error and lambda is not triggered

The webpack.config.js dev server: (with an attempted CORS and preferred proxy solution)

devServer: {
      http2: false,
      writeToDisk: true,
      compress: true,
      hot: true,
      hotOnly: true,
      watchOptions: {
        poll: true
      port: 8080,
      inline: true,
      disableHostCheck: true,
      historyApiFallback: true,
      allowedHosts: [ // obviously for testing and local development only
      proxy: {
        "/api": { // for localhost:8080/api
          target: "http://localhost:9002/2015-03-31/functions/function/invocations",
          secure: false
        "http://localhost:9002/2015-03-31/functions/function/invocations": {
          target: "http://localhost:9002/2015-03-31/functions/function/invocations",
          secure: false
      headers: { // for a silly, attempted CORS solution
        'Access-Control-Allow-Origin': '*',
        "Access-Control-Allow-Methods": "*",
        "Access-Control-Allow-Headers": "*"
      contentBase: path.join(__dirname, 'dist'),

Ideally this would be solved without any CORS (even if just for local development).
I’ve also run into multiple simply calling the URL such as:

curl -XGET "http://localhost:9002/2015-03-31/functions/function/invocations"  // fails
curl -XGET "http://localhost:9002/2015-03-31/functions/function/invocations"  -d "{}" // works but shouldn't because the GET should not include "body". Same for other call types as well.

I cannot tell if I’m simply fighting a CORS problem and/or if the "amazon/aws-lambda-nodejs:14" image has some rather annoying quality of life issues.

Any guidance on why the lambda functions cannot be successfully called would be greatly appreciated.

Source: Docker Questions

Categorised as cors, docker, lambda, node.js, webpack Tagged , , , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us