Skip to content

crash: "Unexpected token a in JSON at position 0" #14

@dsilvasc

Description

@dsilvasc

🐛 Bug description

I have a rust lambda function that replies with this json:

{"statusCode":200,"headers":{"content-type":"application/json"},"multiValueHeaders":{"content-type":["application/json"]},"body":"{\"message\":\"\",\"request_parts\":{\"method\":\"GET\",\"uri\":\"https//wt6mne2s9k.execute-api.us-west-2.amazonaws.com/test/hello\",\"version\":\"HTTP/1.1\"}}","isBase64Encoded":false}

I checked that the lambda function works this way, where apigw.json is the example from the aws docs:

$ FN=the_function_name
$ TARGET=x86_64-unknown-linux-musl
$ cargo install cross
$ CARGO_HOME=$HOME/.cargo-$TARGET cross build --target $TARGET
$ docker run -e DOCKER_LAMBDA_USE_STDIN=1 $PWD/target/$TARGET/debug/$FN:/var/task/bootstrap:ro,delegated lambci/lambda:provided $FN < apigw.json

I changed my serverless.yaml runtime to "provided" to work around #13

The localhost server crashes when I call it:

$ serverless localhost
Serverless: Starting server...
Serverless: Listening on port 3000...
Serverless: ❯ Function routes
Serverless: * world
Serverless:     get http://localhost:3000/
START RequestId: ad30d60c-dc9d-112e-926d-dced0bcc3b4d Version: $LATEST
END RequestId: ad30d60c-dc9d-112e-926d-dced0bcc3b4d
��REPORT RequestId: ad30d60c-dc9d-112e-926d-dced0bcc3b4d	Init Duration: 100.44 ms	Duration: 0.73 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 7 MB

�{"errorType":"exitError","errorMessage":"Req

  Syntax Error -------------------------------------------

  SyntaxError: Unexpected token a in JSON at position 0
      at JSON.parse (<anonymous>)
      at Localhost.module.exports.Localhost.respond (node_modules/serverless-localhost/src/index.ts:95:23)
      at Localhost.<anonymous> (node_modules/serverless-localhost/src/index.ts:200:18)
      at step (node_modules/serverless-localhost/dist/index.js:32:23)
      at Object.next (node_modules/serverless-localhost/dist/index.js:13:53)
      at fulfilled (node_modules/serverless-localhost/dist/index.js:4:58)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

In debug mode I get a response, but still unexpected:

$ DEBUG=localhost serverless localhost
  localhost pinging docker daemon +0ms
Serverless: Starting server...
Serverless: Listening on port 3000...
Serverless: ❯ Function routes
Serverless: * world
Serverless:     get http://localhost:3000/
  localhost Creating docker container for ${func.handler} +1s
  localhost Invoking world function in 105f5785ba47f677f33853f91082421df430e62cd201a65e256c3d2cb1ec5f84 +127ms
  localhost Fetching container logs of 105f5785ba47f677f33853f91082421df430e62cd201a65e256c3d2cb1ec5f84 +1s
START RequestId: bf5bc498-ba27-172b-6a9b-67b47a603943 Version: $LATEST
END RequestId: bf5bc498-ba27-172b-6a9b-67b47a603943
REPORT RequestId: bf5bc498-ba27-172b-6a9b-67b47a603943	Init Duration: 36.19 ms	Duration: 0.82 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 7 MB
  localhost raw function response '
  localhost {"errorType":"exitError","errorMessage":"RequestId: bf5bc498-ba27-172b-6a9b-67b47a603943 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}
  localhost ' +8ms

  localhost function invocation yieled unhandled error +0ms
  localhost Deleting container 105f5785ba47f677f33853f91082421df430e62cd201a65e256c3d2cb1ec5f84 +2ms

🌍 Your environment

serverless version: 1.60.4
serverless-localhost version: 0.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions