Function

Function nodes execute functional code when they receive a message. They can output new messages to further nodes and respond to calling nodes.

Message Formats

There are no expectations on the format of input, output, or response messages.

Environment

  • Runtime: Python (version 2.7 and 3.6), Node.js, Java, or .NET Core
  • Networking Out: The function can make any outbound TCP network connections except to port 25 as an anti-spam measure
  • Networking In: Inbound network connections are blocked, but nodes may handle HTTP requests via the Rest Api node
  • Scratch Space: 500 MB of space is available for use in /tmp

Compute Power, Memory, and Bandwidth limits

The memory allocated to the function process can be configured from 128 MB to 3,008 MB. Compute power and bandwidth increase in proportion to the memory limit.

Errors

The following conditions will generate an error:

  • Uncaught exception
  • Execution timeout
  • Python
    • Handler raises an exception
  • Node.js
    • done callback is called with a truthy error argument
    • Process exits before finishing handling the message (i.e. before the done callback is called)
  • Java
    • Handler throws an exception
  • .NET
    • Handler throws an exception
    • Returned Task is canceled or faults

Errors are propagated in one of two ways:

  • If the Function was called synchronously by another Function node, the error is sent back to the calling Function node.
  • In all other cases, the error is emitted out of the Errors node if one exists in the stack.

Output Port Connections

Stackery enables easy service discovery by connecting Function output ports to the input ports of other nodes. When the Function is created, an environment variable named STACKERY_PORTS is added with JSON encoded information for all the connected resources. The STACKERY_PORTS JSON representation is a two-dimensional array of resource information. Take the following Function node as an example:

hapi

This will generate a JSON representation of the wired connections like the following:

[
  [
    {
      "type": "stream",
      "id": "8gf7fd8g",
      "name": "Transactions",
      "streamName": "stackery-9283478923479-Stream8gf7fd8g",
      "streamArn": "arn:aws:kinesis:us-west-2:123456789012:stream/stackery-9283478923479-Stream8gf7fd8g"
    },
    {
      "type": "objectStore",
      "id": "3ljrk3k3",
      "name": "Persisted Data",
      "bucket": "stackery-9283478923479-objectstore3ljrk3k3-98fgiuiugy3",
      "bucketArn": "arn:aws:s3:::stackery-9283478923479-objectstore3ljrk3k3-98fgiuiugy3"
    }
  ],
  [
    {
      "type": "table",
      "id": "7444hfj7",
      "name": "Records",
      "tableName": "stackery-9283478923479-7444hfj7",
      "tableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/stackery-9283478923479-7444hfj7"
    }
  ]
]

With this data the Function node can easily interact with the connected resources using the AWS SDK.

For more details on data provided in STACKERY_PORTS, see the “Stackery Port Data” section of each resource type’s documentation.

Settings

Name

A label used for the node in the canvas and for the location of the source code inside the git repository for the stack. The source code for a function can be found in /Stackery/functions/<name>.

Outputs

The number of output ports. Messages are output to nodes connected to a port.

Timeout

The maximum amount of time the function can spend executing in response to a message, ranging from one to 300 seconds (five minutes). An error will be generated if the timeout is reached before the function completes handling the message.

Memory

The amount of memory allocated to the function process, ranging from 128 MB to 1.5 GB. This setting also affects compute power and bandwidth limits.

Runtime

The runtime of the function. Can be either Python, Node.js, Java, or .NET.

Source

The location of the source code. If the location is set to Stackery, the source code for the function resides within the Git repo for the stack in /Stackery/functions/<name>. If the location is set to Git, the source code is pulled from an external Git repo.

handler.py / index.js / Handler.java / Handler.cs

The main handler.py (Python), index.js (Node.js), Handler.java (Java), or Handler.cs (.NET) file may be edited if the source of the code is kept in the Git repo for the stack.

Repo

The repo setting defines the location of the code when the source is set to Git. The repository must be publicly accessible over HTTPS, though basic authentication is supported.

Environment Variables

A list of environment variables. Values may be set statically or referenced from Configuration Stores.

Node.js Runtime

Dependencies

Functions can have dependencies on other files and packages. Within the function code directory local dependencies can be added as individual files and package dependencies can be added via a package.json file. Production dependencies specified in a package.json file are installed when the stack is deployed.

.NET Core Runtime

Dependencies

Functions can have dependencies on other files and packages. Within the function code directory local dependencies can be added as individual files and package dependencies can be added to the Stackery.csproj file. Package dependencies specified in the Stackery.csproj file are installed when the stack is deployed.

Python Runtime

Dependencies

Functions can have dependencies on other files and packages. Within the function code directory local dependencies can be added as individual files and package dependencies can be added via a requirements.txt file. Dependencies specified in a requirements.txt file are installed when the stack is deployed.

Stackery Port Data

When connecting the output of Function node A to the input of Function node B, the STACKERY_PORTS environment variable for Function A will contain the following information:

Property Type Description
type string The type of the connected resource. Always set to function.
id string The Stackery Function node’s ID. Example: abcd1234.
name string The Stackery Function node’s name. Example: Batch Processor.
functionName string The name of the AWS Lambda function. Example: stackery-98237489374-Batch-Processor
functionArn string The AWS ARN of the Lambda function. Example: arn:aws:lambda:us-west-2:123456789012:function:stackery-98237489374-Batch-Processor


See Function Output Port Connections for more details on the STACKERY_PORTS environment variable.

Referenceable Properties

The following properties may be referenced by Function, Docker Service, and Docker Task nodes:

Property Value Example
id Cloud Service Identifier arn:aws:lambda:us-east-1:0123456789012:function:stackery-298374238-api

Try Stackery For Free

Gain control and visibility of your serverless operations from architecture design to application deployment and infrastructure monitoring.