Flogo and Lambda

Embrace serverless computing with Flogo’s first class support for AWS Lambda. Infinitely scale Flogo’s ultralight functions and scale back to zero when not in use with AWS Lambda’s NoOps and seamless scaling capabilities.

We’ll guide you through the set of steps required to build the most basic of functions for deployment to AWS Lambda. The flow you’ll build will be the function you deploy.

Prerequisites

Before we get started there are a few prerequisites that we need to take into account:

  • You’ll need to have the Flogo CLI installed
  • You’ll obviously need an AWS account :)

Create the flogo.json

Every Flogo app starts with a flogo.json file. For this scenario we’ll start with a very simple app that simply logs one line. You can copy the below content and paste it into a file called flogo.json

{
  "name": "lambda",
  "type": "flogo:app",
  "version": "0.0.1",
  "description": "My flogo application description",
  "triggers": [
    {
      "id": "my_lambda_trigger",
      "ref": "github.com/TIBCOSoftware/flogo-contrib/trigger/lambda",
      "settings": {
      },
      "handlers": [
        {
          "actionId": "my_simple_flow",
          "settings": {
          }
        }
      ]
    }
  ],
  "actions": [
    {
      "id": "my_simple_flow",
      "name": "my simple flow",
      "ref": "github.com/TIBCOSoftware/flogo-contrib/action/flow",
      "data": {
        "flow": {
          "name": "my simple flow",
          "attributes": [],
          "rootTask": {
            "id": 1,
            "type": 1,
            "tasks": [
              {
                "id": 2,
                "type": 1,
                "activityRef": "github.com/TIBCOSoftware/flogo-contrib/activity/log",
                "name": "log",
                "attributes": [
                  {
                    "name": "message",
                    "value": "Simple Log",
                    "type": "string"
                  }
                ]
              }
            ],
            "links": [
            ]
          }
        }
      }
    }
  ]
}

Create an app

With the flogo.json created, you can create an app out of it by simply executing one command:

flogo create -f flogo.json lambda

This command will download the Flogo Flow dependencies and create the directory structure for your new app.

Build

To continue you’ll need to change directories to the directory that was just created

cd lambda

We will build an embedded application [-e] option and with target shim [-shim] option using the trigger id as the shim. Note that the AWS Lambda trigger leverages a makefile to kick off the build process, the build process simply builds your Flogo application using the Lambdfa trigger shim and zips the binary for deployment to AWS Lambda.

flogo build -e -shim my_lambda_trigger

Once this command finishes successfully the zip file (handler.zip) will be located in your app src directory (for example /path/to/app/lambda/src/lambda/handler.zip).

And deploy…

Deploy to AWS providing the following configuration

  • Runtime: Go 1.x
  • Handler: handler (this is the name of the executable file)