Monkey Island Battles and WebKit
I’ve been wanting to try AWS Lambda for a while. To be honest I’ve not yet done so due to laziness: my experience with AWS is that it needs more configuration and tweaking than I care for. Give me a Heroku any day (pros and cons, lengthy discussion for another day).
That got me started: sure there must be alternatives, something akin to “Heroku for Lambdas”? Yes, I’m aware AWS Lambdas are simple to use, but well, procrastination… So I started looking for options and I landed on a Quora question which pointed me to WebTask.io.
WebTask.io sounds exactly like what I was looking for. And, oh boy, it is simple to use!
I followed their instructions to install their cli, which gives you a very intuitive command
wt with options you’d expect (create, rm, ls). In just a few minutes I had my own endpoint running. Neat.
Now I needed something to test this a bit more. Enter Monkey Island. If you have played those games you most likely remember their Insult Sword Fighting scenes. Even if you didn’t play it you may know what they are, due to popularity in certain circles.
Implementing a service that given a specific insult returns the correct answer seemed like a very straightforward task that would let me test the service and find any obvious hurdles. So that’s what I built; you can get the code in my github repo.
The service has a very basic behaviour:
- If you just call the endpoint (GET request), returns a random pair of insult-answer (in Json)
- If you call the endpoint with an
insultparameter it will return the correct response for that insult
- If you call the endpoint with an invalid/unknown
insultthe response will notify you so
The interaction is all via
GET requests, and it returns
404 codes for invalid insults). As I said, a very basic implementation to test how hard is to use that service (note: not hard at all). Webkit provides the tools to implement all this properly, it’s just I didn’t use them ;)
Testing the service
I published a Webtask endpoint at:
Be aware it is under a free plan, so it may be rate limited and disappear in 30 days. If you want to try it yourself, remember the sample code is available in my github repo.
Let’s see how it works. If we run the request without any additional parameter, we should obtain a random pair of insult-response.
We can provide a parameter with our insult to receive the right response:
&insult=You re the ugliest monster ever created!
which, as expected, returns:
If we provide an insult that is not recognised, like:
the lambda complains:
Working as expected!
To be honest, I just wanted to dabble with this so I didn’t put much more effort into it. An obvious improvement is to allow the user to fight against the machine, although this would require preserving some state in the server-side.
Fortunately WebTask provides limited support for storage, which could be used to manage score for a given user, storing all the information in a map. But there’ll be concurrency issues with very low loads, so it may not be such a good idea after all. Something stateless like left-pad.io fits the lambda model better ;)
As an aside, WebTask mentions in their documentation how their service can be used to enhance the security of your application by hiding api keys and other sensitive resources inside lambdas. It’s an interesting concept worth a bit of research, as it may be a good pattern to adapt in your standard deployment.
In any case, that’s all for now. As always, feedback via Twitter/Email is more than welcome. Cheers!