top of page
Search
  • Writer's pictureTim Burns

A Dungeon Master's API Gateway

Every good adventure starts with a door. Perhaps the door is more than a door, but a gateway to some enchanted temple.


As a Dungeon Master, I want my software gateways to be as interesting as a D&D game. Sometimes a mysterious door leads to a hidden gem like Handling arbitrary HTTP requests in Amazon API Gateway


It's a good document because it cuts through all the complexity of AWS serverless functionality and exposes what API developers really need. I did what any good dungeon master does, and took the source material and made it my own.


Mr. Eric Johnson, the author of the document really nailed the serverless use case.

  • Flexible URL Patterns that allow any path

  • Reproducible deployment patterns for real-world applications

  • A thorough discussion of the challenges of HTTP APIs

I won't rewrite the article, but I will spice up my own version with a bit of D&D flair for those who might get bored writing versions of "Hello World."


To start off with: A Dungeon Master needs dice. And of course, the world needs yet another program to roll dice.



Cutesy? Perhaps. Gratuitous regular expressions and a happy path that takes expressions to match 2d4+2 with the regular expressions

  • ([0-9]+) - any amount of numbers from 0 to 9

  • d - a "d" character

  • ([0-9]+) - any amount of numbers from 0 to 9

  • ([\\+,\\-]?[0-9]*) - an options + or - a number

So 2d4+2 or 1d20 or 3d6-1 all match the regular expression "([0-9]+)d([0-9]+)([\\+,\\-]?[0-9]*)"


But a function without a gateway is like a dungeon with no door. No one can enter to see what wonders it holds.


That's where API Gateway comes in. API Gateway is a technology by AWS that allows you to publish functions to the internet for others to enjoy.


The key to publishing the information is an AWS service called "Cloud Formation." It allows the developer to write a template that securely matches a function with a URL endpoint.


The template contains three parts.


The API definition to utilize OpenAPI 3.0 specifications to create REST functions for the world.


The function definition to map the API to the Python program for rolling the dice.

And a security description to allow the Lambda function to execute within a Virtual Private Cloud and write logs out in case something goes wrong.



Putting it all together we can use a technology called cloud formation to compile the directives above into a working Web API.

The directives above will build version of the deployment and I use Blue and Green for staged alternate deployments. More on that with CI/CD. I use VPC to keep environments separate for security reasons.


The code is all available on Github.

9 views0 comments

Recent Posts

See All
bottom of page