v0.2 - last updated November 2020
If you want to read why AWS is part of the SJGAR stack read the Introducing the SJGAR stack post.
Amazon entered the cloud market in 2006 and have since managed to keep their lead as the largest cloud provider . Amazon introduced serverless compute in the form of AWS Lambda in November 2014. AWS has managed to keep its lead in this field by introducing new services and improving existing ones relentlessly. Amazon is known for their focus on their customers. Not driven by sales targets, their solution architects have KPIs that are based on how successful you are. Even stronger, these architects are said to have bonuses paid out to them when they help their customers save money. Pair this with their self-service capabilities and pay as you go fee model to build autonomous teams that create rock solid software that scales from zero to millions of customers with ease.
AWS offers a lot of services for all types of use cases and architectures. As of 2020, according to Amazon, offers over 175 services. The SJGAR stack helps filter this list down to make it easier to get started. Al services listed below can be tried out for free using the free tier of AWS.
- AWS Lambda
- Amazon DynamoDB
- Amazon API Gateway
- AWS AppSync
- Amazon Cognito
- Amazon S3
- Amazon CloudWatch
- Amazon SNS
- Amazon SQS
- Amazon EventBridge
- AWS Step Functions
- Amazon Cloudfront
- Amazon Route 53
Amazon has a lot of getting started documentation that involves clicking around in the AWS Console. If you invest once into learning the Serverless Framework or CDK you will see that these Infra-as-code tools not only help with production use cases. The community has embraced this at large, with blog posts commonly using these tools instead of clicking around in a web browser.
The Serverless framework
The Serverless Framework was published in 2015. Initial versions were a bit rough around the edges but the APIs have matured. The Serverless Framework has become the most popular IaC for serverless architectures on AWS.
When compared to Terraform it becomes clear that Terraform is much closer to the metal and better suited for more traditional architectures. Deploying a production quality Node.js Lambda service requires much more boilerplate code when compared to the Serverless Framework.
The infrastructure is defined in YAML files and deployed using the serverless CLI. There is a rich community and an array of plugins to help with different workflows. For instance serverless-webpack helps with production quality bundling of your Node.js app. Another example is serverless-offline which allows engineers to start functions on their local machine to help with iterating faster.
AWS CDK (Cloud Development Code)
Recently infra-as-real-code is gaining ground. The AWS CDK is an example of such a tool. Instead of defining infrastructure through YAML definitions, you write a CDK app in a language such as JavaScript or TypeScript. This allows you to re-use all constructs and tools you are already familiar with. Conditional logic and the use of variables are much to easier to do when compared with YAML files. Also testing your infra code becomes possible.
Note, because this is a recent development, you will find a smaller community which means you will have to find out more on your own.
Take your Node.js code and make it run in the cloud. What kind of applications does this have? Almost any. Lambda has some limits like a 15 minute max timeout or a burst concurrency of between 500 and 3000. Even with these limits Lambda should still be able to fulfill needs in 90+ percent of cases.
Think of:
- API's (REST and GraphQL)
- Event Handling code (with DynamoDB triggers, SNS/SQS or EventBridge)
- Scheduled jobs
- Webhooks
- Any server side code
Run scheduled cron-like jobs
Lambda has the built-in ability to be triggered on a schedule. You can specify a rate, like:
- Every 5 minutes: rate(5 minutes)
- Every hour: rate(1 hour)
- Every seven days: rate(7 days)
Alternatively you can specify a cron expression:
- 10:15 AM (UTC) every day: cron(15 10 * * ? *)
- Every 10 min on weekdays: cron(0/10 * ? * MON-FRI *)
- 8:00 AM on the first day of the month: cron(0 8 1 * ? *)
Create a GraphQL microservice with AWS Lambda and apollo-server-lambda
If you want to create a GraphQL service (think service, not server) with AWS Lambda there are multiple options. The option with the least lock-in would be to use Apollo Server. Read the Deploying with AWS Lambda section at the Apollo docs to find out how easy it is to get started.
Besides using Apollo Server you can also use AppSync, the managed GraphQL service provided by AWS. Benefits are easier integration with DynamoDB for persistance, and Cognito for authorization. Another large benefit is support for GraphQL subscriptions come out of the box.
A downside is having to learn and write VTL instead of JavaScript for the mappings.
- Find out about the H2'19 Cloud market share in this IDC Publication
- AWS Lambda function scaling at amazon.com
- AWS Lambda quotas at amazon.com
- AWS Lambda: Schedule expressions using rate or cron at amazon.com
- AWS Modern Applications at amazon.com