Run StackStorm Exchange actions as AWS Lambda functions. Serverless and Stormless. 100% Open Source.

December 14, 2017

by Dmitri Zimine

StackStorm Exchange is an open source catalog of reusable actions. Integrations with everything ranging from common-man DevOps tools, suit and tie services like ServiceNow and Remedy to cool kids like Slack or Twilio, to more exotic systems like HUE Lights and Tesla cars. At the time of writing, there are 6500+ actions spread across 130 integration packs. It is Open Source, with a great community of maintainers. Something that makes StackStorm a great wiring tool to build automations integrating a wide breadth of domains.

But if you’ve taken a red pill and gone wholesale on AWS running serverless, deploying StackStorm may be not an option. Yet the catalog of reusable functions to integrate with commonly used services is an appealing idea. C’mon there should be 1000 Slack lambdas and 10,000 Twilio lambdas out there already, it doesn’t feel creative to write 10,001? Jealous to Azure with their great library of reusable connectors? Why can’t YOU grab something ready-to-use?

Now you can! Run StackStorm Exchange actions as lambda functions. Without StackStorm. Serverless and Stormless.

Consider a detailed tutorial “Building a community sign-up app with Serverless, StepFunctions, and StackStorm Exchange” to really get your hands dirty and try this out for real.

You’ll need AWS account and Serverless Framework – the most popular serverless framework (errr… I struggle with this sentence but yes, they called it “Serverless Framework”, so watch Caps to tell apart a buzzword from the framework). If you’ve gone serverless (buzzword) you’re likely using Serverless (framework) already. If you haven’t picked one yet, Serverless is a safe choice.

The framework is a CLI toolkit for deploying and operating serverless architectures, with a pitch line – drums… – “Focus on your application, not your infrastructure”. You write your functions as JavaScript, Python, Java, or Go, and point to them in a serverless.yml file. The framework does all the infrastructure work to forklift your functions to the cloud, and offers convenient CLI tools that make serverless development workflow fast and enjoyable.

With our new serverless-plugin-stackstorm, you can just point to an action from any integration pack available on StackStorm Exchange. Like this:

# serverless.yml ... functions: # With classic Serverless Python function, # point handler to an entrypoint in your python code: hello_world: handler: handler.hello # With serverless-plugin-stackstorm, # point to an action in a pack from StackStorm Exchange: get_github_issue: stackstorm: action: github.get_issue # <pack.action> ...

Under the hood, the plugin pulls the integration pack from StackStorm Exchange, builds a python bundle, deploys it on AWS and turn the action to Lambda, mapping the input and output as desired. Don’t be scared when you see a Docker container spinning up: we use it for a build environment to make sure the lambdas will be binary compatible no matter what OS you’re using in development.

For detailed instructions see the plugin’s README.md. For some technical highlights, read on.

Or jump straight to playing with it – and if you like the idea, please give it a star! Star

Q: Do I need to run StackStorm to use it?

No. It’s Stormless. We reuse StackStorm action-runner runtime to execute actions on AWS Lambda, but it’s already part of the plugin and you don’t have to care. If you are curious about StackStorm – grab the StackStorm Docker container and play with it. It will help if you want to build packs and contribute to StackStorm Exchange, but it’s not required.

Q: Can I still write a function myself?

Yes, you can and you sure will. The business logic goes to your code, and repeatable plumbing comes from reusable integration packs. On this token: once you write something that might be reusable by community, post it up to Exchange for good Open Source karma. We also send nice stickers, mugs and T-shirts!

Q: How do I know what the action parameters are?

Use the info –action . Like this:

sls stackstorm info --action slack.post_message

Q: But what if my event payload doesn’t match action parameters?

We offer transformation with Jinja syntax to transform the payload to action input: look at the example below. Notice that you can also do this to transform the action output to your desirable shape.

# serverless.yml ... functions: get_issue: events: - http: method: GET path: issues/{user}/{repo}/{issue_id} # Sample event payload: # { "pathParameters": # {"user": "StackStorm", "repo": "st2", "issue_id": "3785"} # } stackstorm: action: github.get_issue input: user: "{{ input.pathParameters.user }}" repo: "{{ input.pathParameters.repo }}" issue_id: "{{ input.pathParameters.issue_id }}" output: statusCode: "{{ 200 if output.exit_code == 0 else 500 }}" body: "{{ output.body }}" state: "{{ output.state }}" full_output: "{{ output }}"

Q: Can I debug and run StackStorm exchange functions locally?

Yes you can:

sls stackstorm docker run --function get_issue \ --verbose \ --passthrough \ -d '{"pathParameters": {"user": "StackStorm", "repo": "st2", "issue_id": "3785"}}'

Note the --passthrough option that let you omit action body invocation – this comes in handy when testing or debugging the parameter transformation.

And --verbose will output the details on the input and output transformations:

One nugget here: you’ll notice syntax that is different from classic serverless invoke local . We run locally in a Docker container for better compatibility with actual AWS Lambda execution environment.

Q: Is this the only nugget? What else should I be aware of?

The plugin is hot off the press: we are still improving UX, refining syntax and CLI, speeding up builds and local experience. But once the function is deployed, it’s just your standard AWS Lambda, and as rock-solid as any Lambda. And if you see something – say something: file bugs, share irritations, propose improvements. PRs are the most welcome!

We are also happy to share that we are bringing Serverless community developers to StackStorm Exchange as reviewers and co-owners. Both communities – StackStorm and Serverless – will greatly benefit from a growing catalog of reusable functions for your projects, 100% Open Source.

Let’s rock! Ping us on StackStorm Slack (signup here) or Serverless Gitter, or on Twitter @Stack_Storm & @goserverless with your feedback.



