Invalid JSON Payload in Lambda invoke mock API response when LAMBDA_REMOTE_DOCKER=true

Issue #51 resolved
Marco Lüthy created an issue

According to the AWS Lambda documentation, the Payload parameter in the response data of the invoke API should be JSON.

From the docs:

Payload — (Buffer, Typed Array, Blob, String)
It is the JSON representation of the object returned by the Lambda function. This is present only if the invocation type is RequestResponse.

However, when LAMBDA_REMOTE_DOCKER=true, the Payload includes what looks like CloudWatch-esque logging:

$ aws --endpoint-url=http://localhost:4574 lambda invoke --function-name poopypants --payload "{}" result.json
{
    "StatusCode": 200
}
$ cat result.json
START RequestId: d7d493d2-d453-12e6-1611-eafc69699401 Version: $LATEST
END RequestId: d7d493d2-d453-12e6-1611-eafc69699401
REPORT RequestId: d7d493d2-d453-12e6-1611-eafc69699401  Duration: 10.69 ms  Billed Duration: 100 ms Memory Size: 1536 MB    Max Memory Used: 29 MB
{"foo":"bar","dateTime":"2017-07-07T14:38:50.050Z"}

The JSON response from the mocked invocation API looks like:

{"StatusCode":200,"Payload":"\u001b[32mSTART RequestId: 3ad48bd3-c79a-1486-e6e8-cb58f9719383 Version: $LATEST\u001b[0m\n\u001b[32mEND RequestId: 3ad48bd3-c79a-1486-e6e8-cb58f9719383\u001b[0m\n\u001b[32mREPORT RequestId: 3ad48bd3-c79a-1486-e6e8-cb58f9719383\tDuration: 18.88 ms\tBilled Duration: 100 ms\tMemory Size: 1536 MB\tMax Memory Used: 28 MB\t\u001b[0m\n{\"foo\":\"bar\",\"dateTime\":\"2017-07-07T14:45:17.767Z\"}"}

This breaks tools like Serverless which expect JSON in the Payload.

Vaguely related to #50?

My docker-compose.yml file:

version: '2.1'

services:
  localstack:
    image: atlassianlabs/localstack
    ports:
      - "4567-4582:4567-4582"
      - "8080:8080"
    environment:
      - SERVICES=${SERVICES- }
      - DEBUG=${DEBUG- }
      - DATA_DIR=${DATA_DIR- }
      - LAMBDA_EXECUTOR=docker
      - LAMBDA_REMOTE_DOCKER=true
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - DOCKER_HOST=unix:///var/run/docker.sock
      - DEFAULT_REGION=eu-west-1
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

Comments (3)

  1. Log in to comment