Wanna go straight to the result, a guestbook using aws Lambda Functions: here.
Some more detail:
I implemented business logic for lambdas at work before. But when I did the infrastructure to deploy and run the lambda was already in place. So I wanted to start from scratch with a simple example.
This awesome guide allowed me to quickly move forward and have this set up in a day.
I created a guestbook page on which people can leave a comment and check out earlier comments. The comments are stored in a nosql database, DynamoDB on aws. Reading from or writing to this guestbook database is done by using two Lambda functions. An api gateway exposes these Lambdas and directs traffic depending on the method type of the incoming request. The Lambda functions forward their logs to Cloudwatch. The frontend calls the API Gateway with an Ajax request. I’m deploying the Lambda Functions using Apex. Check out the result and leave your own comment here: https://nickvanhoof.com/a-lambda-guestbook. I quickly puzzled together a frontend so it might not be as responsive as I’d like it to be.
Detail of a Lambda Function:
If you are the first one to use the guestbook in fifteen minutes time, it will take a little longer to load the page.
-> The lambda is ‘cold’. And aws is spinning it up first. If you call it a second time, the response time will be much higher. I could create a rule in CloudWatch Events to ping the lambda every ten minutes. But that might make you less aware of the fact that you are using Lambdas when posting a comment.
You might not immediately find your message when you posted it. That’s because the messages are returned unordered. I’ve implemented the read Lambda Function to scan the DynamoDB for the first 100 hits. If I wanted to return in order I’d have to query on the DynamoDB with date as a primary or secondary key.
The source code is available on my github: https://github.com/Nxtra/Guestbook