github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/docs/lambda/test.md (about)

     1  # Testing the Lambda Docker images
     2  
     3  The `test-function` subcommand can pass the correct parameters to `docker run`
     4  to run those images with the payload and environment variables set up
     5  correctly. If you would like more control, like mounting volumes, or adding
     6  more environment variables this guide describes how to directly run these
     7  images using:
     8  ```sh
     9  docker run
    10  ```
    11  
    12  An example of a valid `test-function` command would look as follows:
    13  ```
    14  fn lambda test-function user/my-function --payload='{"firstName":"John", "lastName":"Yo" }'
    15  ```
    16  
    17  ## Payload
    18  
    19  The payload is passed via stdin.
    20  It is also possible to pass the payload by using the `payload` argument. Using it the payload is written to a random, opaque directory on the host.
    21  The file itself is called `payload.json`. This directory is mapped to the
    22  `/mnt` volume in the container, so that the payload is available in
    23  `/mnt/payload.json`. This is not REQUIRED, since the actual runtimes use the
    24  `PAYLOAD_FILE` environment variable to discover the payload location.
    25  
    26  
    27  ## Environment variables
    28  
    29  The `TASK_ID` variable maps to the AWS Request ID. This should be set to
    30  something unique (a UUID, or an incrementing number).
    31  
    32  `test-function` runs a container with 300MB memory allocated to it. This same
    33  information is available inside the container in the `TASK_MAXRAM` variable.
    34  This value can be a number in bytes, or a number suffixed by `b`, `k`, `m`, `g`
    35  for bytes, kilobytes, megabytes and gigabytes respectively. These are
    36  case-insensitive.
    37  
    38  The following variables are set for AWS compatibility:
    39  * `AWS_LAMBDA_FUNCTION_NAME` - The name of the docker image.
    40  * `AWS_LAMBDA_FUNCTION_VERSION` - The default is `$LATEST`, but any string is
    41    allowed.
    42  * `AWS_ACCESS_KEY_ID` - Set this to the Access Key to allow the Lambda function
    43    to use AWS APIs.
    44  * `AWS_SECRET_ACCESS_KEY` - Set this to the Secret Key to allow the Lambda
    45    function to use AWS APIs.
    46  
    47  ## Running the container
    48  
    49  The default `test-function` can then be approximated as the following `docker
    50  run` command:
    51  
    52  ```sh
    53  mkdir /tmp/payload_dir
    54  echo "<payload>" |
    55  docker run -v /tmp/payload_dir:/mnt \
    56             -m 1G \
    57             -e TASK_ID=$RANDOM \
    58             -e TASK_MAXRAM=1G \
    59             -e AWS_LAMBDA_FUNCTION_NAME=user/fancyfunction \
    60             -e AWS_LAMBDA_FUNCTION_VERSION=1.0 \
    61             -e AWS_ACCESS_KEY_ID=<access key> \
    62             -e AWS_SECRET_ACCESS_KEY=<secret key> \
    63             --rm -it
    64             user/fancyfunction
    65  ```