One of the most interesting trends I’ve come across recently is Serverless compute. That is, running your custom code in the cloud without the need to provision or maintain a server to run it on.
To lean more about this I decided to build a webapp using AWS Lambda. I wanted a bit more than the typical “Hello World”, something I could show doing useful work rather than just returning a hard coded string. But I also didn’t want to spend time developing an app when this is not really about that.
So I settled on building a Subnet Calculator (something close to my heart working for an ISP). It’s super-simple, but useful enough that I’m going leave it up (unless the AWS bill gets too much!).
The basic design is:
- A single page HTML and Javascript app as the front end, hosted on AWS S3,
- This makes calls to the AWS API Gateway,
- Which invokes the AWS Lambda function. [IMAGE]
Step One: The Lambda Function
Setting up the actual Lambda function was actually the easiest part of this whole exercise: In the AWS console go to Lambda in the Compute section, click the Create function button. Give the function a name and chose which runtime to use. Lambda supports a few languages, I used Python 3.6 for this project. Finally either create a new IAM role or select an existing role with permissions to execute Lambda functions.
Now you write the code you want to execute when the function is triggered. If you need to use third party libraries or other dependencies, you can package these all up together as a zip file and upload it (there are good instructions for this here). Or you can just write directly into the online code editor (which is actually pretty good).