@cumulus-test/sled
v1.0.2-beta.0
Published
Protocol wrapper for Cumulus JS files
Readme
Cumulus sled (Javascript)
Implements an AWS Lambda handler that adapts incoming messages in the Cumulus protocol to a format more easily consumable by Cumulus tasks, invokes the tasks, and then adapts their response back to the Cumulus message protocol to be sent to the next task.
Tasks being run within a sled are written as AWS Lambda handlers themselves, receiving
the usual event, context, and callback arguments. Their event object, however,
contains only two keys:
input: The task's input, typically thepayloadof the message, produced at runtimeconfig: The task's configuration, with any templated variables resolved
Tasks return or call back with their logical output, which typically goes in the payload
of the resulting Cumulus message.
Expectations for input, config, and return values are all defined by the tasks, and should be well documented. Tasks should thoughtfully consider their inputs and return values, as breaking changes may have cascading effects on tasks throughout a workflow. Configuration changes are slightly less impactful, but must be communicated to those using the task.
Examples
example/ contains an example handler that prints some diagnostics and returns its event.
example/messages/ contains example inputs and outputs produced by the handler.
To run the example, execute node index.js local <message-name> in this directory, where
<message-name> is the basename of the example message under example/messages/ to use as input
and output, e.g. basic or jsonpath.
Use
To use the sled:
Update the task in question to accept/return the above inputs and outputs. Remove all code dealing with the Cumulus message protocol.
Add a
cumulus.jsonfile to the root of the task. It should look like the following:{ "task": { "entrypoint": "my-module.my_handler" } }Where the
entrypointspecifies the task's handler function, identical to how it would be provided to AWS Lambda. If not defined, the sled will assume thatindex.handlershould be used (the Lambda default).Create a zip file of the task, as you ordinarily would for AWS Lambda
Run
npm run buildin this directory. A minimal set of code will be produced in thedistdirectory.Copy the contents of the
distdirectory (a directory namedcumulus-sled) into the task's zip fileUpload the zip file to AWS Lambda, and specify the Lambda
Handlerascumulus-sled.handlerPut it in a Cumulus workflow!
Why?
This implementation has a few major advantages over the previous library-based approach:
- It's very low overhead. It requires no transpilation, and the deployed code size is only around 100KB
- It explicitly prevents tasks from making assumptions about data structures like
metaandcumulus_metathat are owned internally and may therefore be broken in future updates. To gain access to fields in these structures, tasks must be passed the data explicitly in the workflow configuration. - It provides clearer ownership of the various data structures. Operators own
meta. Cumulus ownscumulus_meta. Tasks define their ownconfig,input, andoutputformats. - The sled greatly simplifies running Lambda functions not explicitly created for Cumulus. Add a
cumulus.json(if needed), update the Lambda to readevent.inputinstead ofevent, and the handler can "speak" Cumulus. - The approach greatly simplifies testing for tasks, as tasks don't need to set up cumbersome structures to emulate the message protocol and can just supply handlers their inputs and outputs.
Contributing
Please feel free to extend and modify the code. Because it is run so many places, it requires more careful testing and review than most other code.
We would love to add support for languages other than Javascript. If you know Python well, please consider helping create a Python sled!
