Skip to content
/ lot Public

Lambda of Thrones - GOT story plot generator written with Apex-Lambda

License

Notifications You must be signed in to change notification settings

edoardo849/lot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda of Thrones

High-Concept GOT story plot generator written for Apex-Lambda, demoing the awesome piping of lambda functions in the Terminal and proposing a logging and monitoring strategy for serverless with ELK.

Introduction

Ever wanted to have Game of Thrones story plots being randomly generated by a Lambda set of functions? No? Well, that's too bad... this compelling need actually comes from a little experiment trying to answer 2 questions:

  1. Is it possible to have a coherent strategy for logging and monitoring Lambda functions?
  2. Is it possible to chain Lambda functions in the Terminal to provide a UNIX-like piping?

Both answers turned out to be yes.

Requirements

For this project to work you'll need to:

  1. have Apex installed on your local machine
  2. have an AWS account with full access to:
  • IAM roles
  • Lambda functions
  • CloudWatch
  1. have GoLang installed on your local machine
  2. have AWS CLI tools installed on your local machine with valid ~/.aws/config and ~/.aws/credentials files
  3. have json - JSON love for your command line installed

Recommended modules

Optionally, if you want to see your logs in ELK :

  1. have an AWS account with further full access to:
  • AWS ElasticSearch
  1. have Sense Chrome extension installed

Installation

Git clone yada yada

From within your GOPATH:

# create the
mkdir $GOPATH/src/github.com/edoardo849 && cd "$_"
# clone the repo
git clone https://github.com/edoardo849/lot

# enter the folder
cd lot

Configuration

Initialise Apex

# set your default profile for AWS and AWS region
source ./config

# run the setup
make setup

# Project name
Project name: lot

# Project description
Project description: Lambda of Thrones

I always find useful to setup the aws profile in the project.json file that apex will generate:

file: ./project.json
{
  "profile":"default",
}

you may still need to source the ./config file for every new bash session though: that's a known bug in apex.

Running the functions

As a shorthand I've set up a Makefile that takes care of everything. If you want to tweak the configuration have a look at it

# run the tests
make test

# deploy the code on AWS Lambda
make deploy

# invoke the functions
make plot

Something like this should come out: hopefully it will make great sense... but most of the time is just silly.

In order to check out the lambda functions that were created, run:

aws lambda list-functions --profile=YOUR-PROFILE --region=YOUR-REGION
_                    _         _                __   _   _
| |    __ _ _ __ ___ | |__   __| | __ _    ___  / _| | |_| |__  _ __ ___  _ __   ___  ___
| |   / _` | '_ ` _ \| '_ \ / _` |/ _` |  / _ \| |_  | __| '_ \| '__/ _ \| '_ \ / _ \/ __|
| |__| (_| | | | | | | |_) | (_| | (_| | | (_) |  _| | |_| | | | | | (_) | | | |  __/\__ \
|_____\__,_|_| |_| |_|_.__/ \__,_|\__,_|  \___/|_|    \__|_| |_|_|  \___/|_| |_|\___||___/


What if Jon Snow drank all the wine of Tywin Lannister after winter came in the Eyre because when dead men come hunting... you think it matters who sits on the iron throne?

Under the hood

So apart from the obvious value of having a random plot generator... this project demonstrate that it's possible to chain lambda functions together in the Terminal to achieve a UNIX-like piping of outputs.

Project structure

All the code is actually in the ./src folder. The Makefile is just replicating the code inside the ./functions folder and replacing a variable to correctly name each function. Each function is called after one of the Five Ws:

  • who
  • what
  • when
  • where
  • why

Now this is of course not optimal... but remember that we just want to chain lambda functions together and to obtain their different logs.

When make plot is called we are actually invoking each lambda function individually passing around the resulting json. The first seed is:

{ "value": "What if" }

In order to try it out, you can copy-paste in the Terminal:

echo '{ "value": "What if" }' | apex invoke who

or be more creative and:

echo '{ "value": "The best character is" }' | apex invoke who | apex invoke why

The complete code from the Makefile is:

echo '{ "value": "What if" }' | \
apex invoke who | \
apex invoke what | \
apex invoke who | \
apex invoke when | \
apex invoke where | \
apex invoke why

You can of course play around and replace the seed data from the ./data folder into whatever you like to produce a valid random phrase generator.

Slides

You can download the slides from Google Slides.

About

Lambda of Thrones - GOT story plot generator written with Apex-Lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published