Using an AWS database with Octoblu

A colleague was recently prototyping an office resource booking and management system using Octoblu. Although Octoblu provided much of the infrastructure necessary to build this system, including mechanisms to store state (such as key-value pairs), this use-case was really crying out for a more heavyweight database, something not directly available within Octoblu. This inspired me to see how easy it would be to connect Octoblu up to a database.

Octoblu is great at calling REST APIs, and AWS has a Lambda blueprint to expose tables hosted on its DynamoDB service via HTTPS APIs using the API gateway service. Setting this up and using it in Octoblu turned out to be fairly straightforward. Here’s what I did:

  1. Use the AWS console to create a DynamoDB table named “OctobluTest” with primary key “username” (String)
  2. Use the AWS console to create a Lambda function using the “microservice-http-endpoint” blueprint
  3. Use the AWS API Gateway console to create an API key named TestKey
    1. Select API => MyDBUpdate; Select stage => prod => add
    2. Record the API key
  4. Create a POST method for the API (same Lambda function – for some reason it created a GET one – probably a mistake I made somewhere)
  5. Redeploy the API to ensure the API key takes effect

octoblueawsdbBack in Octoblu I created a flow to test this. Here the trigger just sends my username as the message payload and the JSON Template node constructs the JSON for the AWS API call ({“operation”:”read”,”payload”:{“TableName”:”OctobluTest”,”Key”:{“username”:”jXXXX”}}}). The HTTP POST node reconstructs the JSON (there’s probably a nicer way to do this in Octoblu but this works well enough) and the AWS API gateway API key is added here as a “x-api-key” header. You can see in the debug window how this has completed the lookup and returned the DB row (just a username to email lookup).

The Lambda blueprint exposes row create, read, update, delete and list operations (not table create – the table must exist already). Figuring out the JSON to use in the calls is a pain – I relied on the examples in http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html

awsdbapi

In conclusion: this exercise demonstrated to me how easy it is to connect Octoblu to cloud resources that have REST APIs. This is not the first time I’ve connected Octoblu and AWS and I’m sure it won’t be the last – these two platforms are enormously powerful and used together create a wealth of automation possibilities.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s