Skip to content

Local testing page: documented request does not work with the documented docker command #38

Description

@peterbjohnson

On docs/advanced/evaluation_functions/local.md (published at https://docs.lambdafeedback.com/advanced/evaluation_functions/local/) the docker run command and the example request are inconsistent, so following the page as written always fails.

The page gives:

docker run --rm -d --name eval-function -p 9000:8080 eval-tmp

then tells you to POST to http://localhost:9000/2015-03-31/functions/function/invocations with:

{ "headers": { "command": "eval" }, "body": { "response": "a", "answer": "a", "params": {} } }

Following that exactly returns {"error":{"message":"invalid method"}}.

Why

The base image entrypoint only starts the AWS Lambda Runtime Interface Emulator when AWS_LAMBDA_RIE is set:

if [ -z "${AWS_LAMBDA_RUNTIME_API}" ] && [ -n "${AWS_LAMBDA_RIE}" ]; then
  exec aws-lambda-rie "$@"
else
  exec "$@"
fi

With the documented docker run that variable is unset, so Shimmy runs in standalone HTTP mode ("detected standalone environment" in the logs) and the /2015-03-31/... path does not exist. The documented endpoint belongs to the emulator, which the documented command never starts.

Two further problems apply even once the emulator is enabled:

  • body must be a JSON-encoded string, not an object. As an object the RIE returns json: cannot unmarshal object into Go struct field APIGatewayV2HTTPRequest.body of type string.
  • The envelope needs requestContext.http.method set to POST, otherwise Shimmy returns invalid method.

Suggested fix

Document the standalone shape as the default, since it matches the docker run command already on the page and is much simpler:

docker run --rm -d --name eval-function -p 9000:8080 eval-tmp
POST http://localhost:9000/
command: eval
Content-Type: application/json

{ "response": "a", "answer": "a", "params": {} }

Response: {"command":"eval","result":{...}}. GET /health also works.

Then, if the Lambda-emulator path is still worth documenting (for reproducing AWS behaviour), show it as a separate section with the two corrections:

docker run --rm -d --name eval-function -e AWS_LAMBDA_RIE=1 -p 9000:8080 eval-tmp
{
  "version": "2.0",
  "rawPath": "/",
  "requestContext": { "http": { "method": "POST", "path": "/" } },
  "headers": { "command": "eval", "content-type": "application/json" },
  "body": "{\"response\":\"a\",\"answer\":\"a\",\"params\":{}}",
  "isBase64Encoded": false
}

Both forms verified against a Python evaluation function built from the current boilerplate; the standalone form returns 200 with the result, and the corrected envelope returns statusCode: 200 with the result JSON-encoded in body.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions