This year I wasnât able to attend re:Invent, but I did want to do something nice in between the live streams and specifically around Serverless compute and AWS Lambda.
Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consumeâââthere is no charge when your code is not running. With Lambda, you can run code for virtually any type of application or backend serviceâââall with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability.
The above snippet from AWS explains very well what Lambda is aimed to do!
To develop your serverless functions you can use many different application frameworks, but did you know that Flogo is one of them? With Project Flogo you can embrace serverless computing with Flogoâs first class support for AWS Lambda. Infinitely scaling Flogoâs ultralight functions and scaling it back to zero when not in use.
In my last article I wrote about how to deploy those ultralight Flogo apps to Kubernetes to use manage your microservices on one of the most powerful container management platforms. In this article I want to go one step further down and deploy them on a Function-as-a-Service platform, AWS Lambda.
Prerequisites #
Before we get started there are a few prerequisites that we need to take into account:
- Youâll need to have Docker installed
- Youâll need to have the latest version of the Project Flogo Web UI installed if you want to graphically create your microservices (and who doesnât right?):
docker run -it -p 3303:3303 flogo/flogo-docker eula-accept - Youâll need to have the Flogo CLI installed
- Youâll obviously need an account for AWSÂ :)
The app #
With the latest version of the Web UI for Project Flogo there are a bunch of new things (the Lambda trigger being one of them). What hasnât changed though is that weâll start with a creating a new microservice and create a new flow within that.

After you click on the flow, youâll be presented with quite a new look and feel to modelling your flow. The flows and the triggers have been separated so that the flows are now very well aligned with the concept of a function. As a developer you can focus on the business logic without worrying on the infrastructure :)

You can click on the â+â sign on the left to add a new trigger âStart Flow as a function in Lambdaâ. This allows your flow to run as a function in Lambda. We wonât need any Flow params for now but we do want to see something in the logs so letâs add a âLog Messageâ activity

Building for Lambda #
To build an app for Lambda, youâll need to export the flow from the Web UI first using the âExport Appâ function. From a terminal window execute
flogo create -f <appname>.json lambdacd lambdaThe above command will create a new folder called âlambdaâ and go get (pun intended) all the dependencies it needs to run your flows. For Lambda we want to build an application with the configuration embedded in the executable and with a shim to instruct the build process to overwrite the entry point for the application using the Lambda Trigger. The argument to -shimindicates the trigger ID to use as the entry point to the flow (function). The AWS Lambda trigger leverages a makefile to kick off the build process and the build process happens within a docker container (hence docker as a prerequisite) because, at the time of writing, Go plugins (.so files) can only be built on Linux. So to build execute:
flogo build -e -shim start_flow_as_a_function_in_lambdaThis command will pull the docker image âeawsy/aws-lambda-go-shim:latestâ locally and build the zip file needed for deployment to AWS Lambda. Once this command finishes successfully the zip file (handler.zip) will be located in your app directory (for example `/path/to/app/lambda/src/lambda/handler.zip`).
Uploading to AWSÂ Lambda #
In the Lambda console you can create a new function and it is important that the runtime is set to âPython 2.7â (the generated shim contains a python executable function that in turn triggers the flow).
As you might have seen during the live streams AWS just announced support for Go, so stay tuned for native triggers as well!
After hitting the create button, youâll be presented with a brand new Lambda function. From the âCode entry typeâ dropdown youâll need to select âUpload a .ZIP fileâ, pick the zip that was just generated and set the Handler to âhandler.Handleâ (without this youâll not be able to trigger your flow). You can leave the other defaults as is and hit the orange âsaveâ button. To see your flow in action send a test event and check the CloudWatch logs

Conclusion #
This was a very simple Flogo app running on AWS Lambda, but you can do incredibly cool things using Project Flogo as the microservices framework that runs on Lambda! If you want to get started yourself, just follow the steps above and let us know what you end up building.
Originally published on hackernoon.com