DEV Community

Cover image for The Elusive Lambda Console; A Specification Proposal.
Ken Collins for AWS Heroes

Posted on • Originally published at lamby.cloud

The Elusive Lambda Console; A Specification Proposal.

After years of smashing Cloud & Rails together, I've come up with an idea. Better than an idea, a working specification! One where us Rails & Lambda enthusiasts can once again "console into" our "servers" and execute CLI tasks like migrations or interact via our beloved IRB friend, the Rails console. Today, I would like to present, the Lambda Console project. An open specification proposal for any AWS Lambda runtime to adopt.

Lambda Console CLI Screenshot

Lambda Console

npm install -g lambda-console-cli
Enter fullscreen mode Exit fullscreen mode

The Lambda Console is a CLI written in Node.js that will interactively create an AWS SDK session for you to invoke your Lambda functions with two types of modes.

  1. CLI Runner
  2. Interactive Commands

Think of the CLI Runner as a bash prompt. You can run any process command or interact with the filesystem or environment. For Rails users, running rake tasks or DB migrations. These tasks assume the Lambda task root as the present working directory.

Interactive commands however are evaluated in the context of your running application. For Ruby and Rails applications, this simulates IRB (Interactive Ruby Shell). For Lamby users, this mode simulates the Rails console. Making it easy for users to query their DB or poke their models and code.

The Proposal

There is nothing about the Lambda Console that is coupled to Ruby or Rails. The idea is simple, as a Lambda community, could we do the following?

  1. Finalize a Lambda Console request/response specification.
  2. Create more runtime-specific language implementations.
  3. Build an amazing CLI client for any runtime.

Here is what we have today. The request specification, a simple event structure that is only a few dozen lines of JSON schema.

{ "X_LAMBDA_CONSOLE": { "run": "cat /etc/os-release" } }
Enter fullscreen mode Exit fullscreen mode
{ "X_LAMBDA_CONSOLE": { "interact": "User.find(1)" } }
Enter fullscreen mode Exit fullscreen mode

Any Lambda runtime code or framework could implement the handling of these event in their own language-specific pakages. You can find the Ruby implementation of these in the Lambda Console's first reference implementations.

The Possibilities

What I really want is an amazing CLI client. The current Lambda Console CLI was hacked together in a few days using some amazing Node.js tools that make building interactive CLIs so so easy. But I've never done this before. If this type of tooling sounds interesting to you and you like Node.js, let me know! It would be amazing to see implementation packages for these for Node, PHP, Python, and other frameworks using these languages. Here are some ideas on where I could see this going.

Live STDOUT & STDERR: We could take advantage of Lambda's new Response Streaming and send output buffers as they happen.

Pseudo TTY: Is there a way to better simulate a real TTY session? Could this even include ANSI colors?

Quality of Life Improvements: Everything from, Allowing the CLI tool to switch modes without restarting it; Creating a command buffer to up arrow navigate history; Prettier UI.

Formal Response JSON Schema: As the features grow, should the response JSON be standardized? For example, if the client wanted to syntax highlight interactive language commands, how would it know what language was being used? We could have a X_LAMBDA_CONSOLE_LANG response header.

What else would you like to see in a Lambda Console client?

Top comments (0)