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

     1  # Environment
     2  
     3  The base images strive to provide the same environment that AWS provides to
     4  Lambda functions. This page describes it and any incompatibilities between AWS
     5  Lambda and Dockerized Lambda.
     6  
     7  ## Request/Response
     8  
     9  IronFunctions has sync/async communication with Request/Response workflows.
    10  * sync: returns the result as the body of the response
    11  * async: returns the task id in the body of the response as a json
    12  
    13  The `context.succeed()` will not do anything with result
    14  on node.js, nor will returning anything from a Python function.
    15  
    16  ## Paths
    17  
    18  We do not make any compatibility efforts towards running your lambda function
    19  in the same working directory as it would run on AWS. If your function makes
    20  such assumptions, please rewrite it.
    21  
    22  ## nodejs
    23  
    24  * node.js version [0.10.42][iron/node]
    25  * ImageMagick version [6.9.3][magickv] and nodejs [wrapper 6.9.3][magickwrapperv]
    26  * aws-sdk version [2.2.12][awsnodev]
    27  
    28  [iron/node]: https://github.com/iron-io/dockers/blob/master/node/Dockerfile
    29  [magickv]: https://pkgs.alpinelinux.org/package/main/x86_64/imagemagick
    30  [magickwrapperv]: https://www.npmjs.com/package/imagemagick
    31  [awsnodev]: https://aws.amazon.com/sdk-for-node-js/
    32  
    33  ### Event
    34  
    35  Payloads MUST be a valid JSON object literal.
    36  
    37  ### Context object
    38  
    39  * context.fail() does not currently truncate error logs.
    40  * `context.functionName` is of the form of a docker image, for example
    41    `iron/test-function`.
    42  * `context.functionVersion` is always the string `"$LATEST"`.
    43  * `context.invokedFunctionArn` is not supported. Value is empty string.
    44  * `context.memoryLimitInMB` does not reflect reality. Value is always `256`.
    45  * `context.awsRequestId` reflects the environment variable `TASK_ID`. On local
    46    runs from `ironcli` this is a UUID. On IronFunctions this is the task ID.
    47  * `logGroupName` and `logStreamName` are empty strings.
    48  * `identity` and `clientContext` are always `null`.
    49  
    50  ### Exceptions
    51  
    52  If your handler throws an exception, we only log the error message. There is no
    53  `v8::CallSite` compatible stack trace yet.
    54  
    55  ## Python 2.7
    56  
    57  * CPython [2.7.11][pythonv]
    58  * boto3 (Python AWS SDK) [1.2.3][botov].
    59  
    60  [pythonv]: https://hub.docker.com/r/iron/python/tags/
    61  [botov]: https://github.com/boto/boto3/releases/tag/1.2.3
    62  
    63  ### Event
    64  
    65  Event is always a `__dict__` and the payload MUST be a valid JSON object
    66  literal.
    67  
    68  ### Context object
    69  
    70  * `context.functionName` is of the form of a docker image, for example
    71    `iron/test-function`.
    72  * `context.functionVersion` is always the string `"$LATEST"`.
    73  * `context.invokedFunctionArn` is `None`.
    74  * `context.awsRequestId` reflects the environment variable `TASK_ID` which is
    75    set to the task ID on IronFunctions. If TASK_ID is empty, a new UUID is used.
    76  * `logGroupName`, `logStreamName`, `identity` and `clientContext` are `None`.
    77  
    78  ### Exceptions
    79  
    80  If your Lambda function throws an Exception, it will not currently be logged as
    81  a JSON object with trace information.
    82  
    83  ## Java 8
    84  
    85  * OpenJDK Java Runtime [1.8.0][javav]
    86  
    87  [javav]: https://hub.docker.com/r/iron/java/tags/
    88  
    89  The Java8 runtime is significantly lacking at this piont and we **do not
    90  recommend** using it.
    91  
    92  ### Handler types
    93  
    94  There are some restrictions on the handler types supported.
    95  
    96  #### Only a void return type is allowed
    97  
    98  Since Lambda does not support request/response invocation, we explicitly
    99  prohibit a non-void return type on the handler.
   100  
   101  #### JSON parse error stack differences
   102  
   103  AWS uses the Jackson parser, this project uses the GSON parser. So JSON parse
   104  errors will have different traces.
   105  
   106  #### Single item vs. List
   107  
   108  Given a list handler like:
   109  
   110  ```java
   111  public static void myHandler(List<Double> l) {
   112      // ...
   113  }
   114  ```
   115  
   116  If the payload is a single number, AWS Lambda will succeed and pass the handler
   117  a list with a single item. This project will raise an exception.
   118  
   119  #### Collections of POJOs
   120  
   121  This project cannot currently deserialize a List or Map containing POJOs. For
   122  example:
   123  
   124  ```java
   125  public class Handler {
   126    public static MyPOJO {
   127      private String attribute;
   128      public void setAttribute(String a) {
   129        attribute = a;
   130      }
   131  
   132      public String getAttribute() {
   133        return attribute;
   134      }
   135    }
   136  
   137    public static void myHandler(List<MyPOJO> l) {
   138      // ...
   139    }
   140  }
   141  ```
   142  
   143  This handler invoked with the below event will fail!
   144  
   145  ```js
   146  [{ "attribute": "value 1"}, { "attribute": "value 2" }]
   147  ```
   148  
   149  #### Leveraging predefined types is not supported
   150  
   151  Using the types in `aws-lambda-java-core` to [implement handlers][predef] is
   152  untested and unsupported right now. While the package is available in your
   153  function, we have not tried it out.
   154  
   155  [predef]: http://docs.aws.amazon.com/lambda/latest/dg/java-handler-using-predefined-interfaces.html
   156  
   157  ### Logging
   158  
   159  The [log4j and LambdaLogger
   160  styles](http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html) that log
   161  to CloudWatch are not supported.
   162  
   163  ### Context object
   164  
   165  * `context.getFunctionName()` returns a String of the form of a docker image,
   166    for example `iron/test-function`.
   167  * `context.getFunctionVersion()` is always the string `"$LATEST"`.
   168  * `context.getAwsRequestId()` reflects the environment variable `TASK_ID` which is
   169    set to the task ID on IronFunctions. If TASK_ID is empty, a new UUID is used.
   170  * `getInvokedFunctionArn()`, `getLogGroupName()`, `getLogStreamName()`, `getIdentity()`, `getClientContext()`, `getLogger()` return `null`.