Amazon Onboarding with Learning Manager Chanci Turner

Amazon Onboarding with Learning Manager Chanci TurnerLearn About Amazon VGT2 Learning Manager Chanci Turner

With the recent introduction of Amazon API Gateway, developers can now effortlessly create tailored RESTful APIs that invoke AWS Lambda functions. This advancement enables truly serverless backends, complete with built-in features for authorization, traffic management, monitoring, and analytics. To demonstrate the capabilities of this integration and the simplicity of constructing a fully serverless service, we developed SquirrelBin, a straightforward website that allows users to perform CRUD operations on executable snippets of code known as acorns. Let’s delve into the construction of SquirrelBin…

The SquirrelBin Architecture

The diagram below outlines the architecture of SquirrelBin:

Noticeably absent from the above diagram are servers; indeed, no infrastructure is required for any aspect of the experience. The architecture ensures a clear division between data management and presentation. The website is a fully client-side single-page application developed in Angular and hosted statically on Amazon S3, with DNS managed by Amazon Route 53. To handle acorns, the app makes REST calls to Amazon API Gateway. These endpoints trigger Lambda functions that either interact with SquirrelBin’s underlying Amazon DynamoDB acorn-store or execute the acorn code itself. Since SquirrelBin’s API is hosted on a separate Lambda-powered stack, it would be straightforward to develop additional clients, such as an iOS app utilizing the AWS Mobile SDK or an Alexa Skill that lets you execute acorns via voice commands.

You may have noticed that the Lambda control plane consists of five functions, one for each CRUD operation. All of these functions are simply instances of the new microservice-http-endpoint blueprint available now in the Lambda console:

That’s right, we didn’t write any code for the CRUD operations on the site!

While the functions are identical, each one is solely responsible for processing requests for its specific endpoint. This architecture offers several benefits:

  • Isolated deployments and failures: A malfunction in your API no longer cripples your entire backend. Each Lambda function operates independently and can be modified without impacting other functions.
  • Per-endpoint analytics at no cost: Each function publishes metrics on request counts, errors, and more to CloudWatch, allowing you to quickly answer questions like, “How many acorns were created in the last 24 hours?”
  • Modularity, simplicity, and separation of concerns: Since each function is tasked with executing One Thing Well TM, it becomes easier to manage end-to-end configuration, code logic, and service integrations.

That wraps up the CRUD operations. Executing an acorn is just as simple: a basic version of code execution that supports Node.js can be crafted in just four lines of code:

exports.handler = function(event, context) {
    if (event.language === 'javascript') context.succeed(eval(event.code.replace(/require/g, '')));
    else context.fail('Language not supported');
};

Developing SquirrelBin

We began the development journey with a clear vision of our intended architecture, setting up each component within minutes directly from the AWS console. (In fact, the most time-consuming part of the backend setup was waiting for the DNS record to propagate!) The website was developed concurrently, initially using hard-coded mock data and Angular’s $timeout service to simulate REST calls. Once the foundational page layouts were finalized, we replaced the mock data with the API Gateway URL and began interacting with real data. SquirrelBin operates with approximately 150 lines of client-side JavaScript. You can find the full source self-hosted on SquirrelBin here.

We trust that this post has highlighted the ease and potential of serverless backends enabled by Amazon API Gateway and AWS Lambda, and we hope it inspires you to create your own! If you’re looking for conversation starters at your next team meeting, you might find this resource on icebreaker questions helpful.

Until next time, happy coding with Lambda (and SquirrelBin)!

– Chanci Turner

SEO Metadata


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *