Going Serverless with 7 Core AWS Services

Hayk Simonyan
Level Up Coding
Published in
6 min readJul 5, 2021

--

In this article, you will learn how to use the different services that AWS offers to build serverless applications without focusing on the infrastructure and provisioning of the services but instead focusing on your code, on main business logic, and your core product.

But wait, what is serverless? Serverless is a development model that allows us to build and run applications without having to manage servers. There are still servers involved but the cloud provider (AWS, Azure, or Google Cloud) handles the routine work of maintaining and scaling the server.

The biggest advantage of the serverless approach is that you pay only for the compute power, storage, and other resources you use without any up-front commitments. Also, your application can scale up based on demand. You have access to compute and storage resources when you need them.

Although there are over 200 AWS services available, you only need 7 core services to start building your first serverless application. Here is the list of them:

  1. API Gateway — API, REST API
  2. Lambda — Logic, Execute code
  3. DynamoDB — Data, Store & Retrieve Data
  4. Cognito — Auth, Authenticate Users
  5. S3 — App, Serve static app
  6. CloudFront (Optional) — Cache, Improve Performance with Caching
  7. Route 53 — DNS, Translate URL

With a serverless approach, you can actually do more than host a backend for an app. If you have a mobile app, you definitely don’t need to host your app, therefore, you can skip the last 3 services. However, if you’re building a web app you can even host it on a server that will scale dynamically using S3, CloudFront, and Route53.

1. API Gateway

API Gateway acts as the gatekeeper for applications to access functionality or data from your backend service. Think of it as a router in your Node.js application. With API Gateway you can create both RESTful APIs and real-time WebSocket APIs.

In addition, it provides a lot of functionality out of the box like API version management, CORS support, authorization, access control, etc, which you have to configure manually in a non-serverless API.

Here’s an overview of how API Gateway works. It takes the incoming requests and passes them to another AWS service, typically to some Lambda function, which returns a response to API Gateway, and then API Gateway returns a response to the client.

2. Lambda

Lambda functions are the controllers of your backend API. The main business logic of talking to databases and returning responses will be here.

It allows you to upload code or container image, automatically allocate compute execution power, and run your code based on the incoming request or event.

AWS Lambda officially supports these programming languages — C#, Go, Java, Node.js, PowerShell, Python, Ruby.

Lambda functions get the request from API Gateway, process them, and return the response to API Gateway. But you are not limited to that you can set up your code to automatically trigger other AWS services or call it directly from any web or mobile app.

3. DynamoDB

DynamoDB is a NoSQL database service. It’s a key-value and document database with built-in security, backup, and in-memory caching for internet-scale applications. It provides low-latency data access at any scale. You can create a new table for your application and let DynamoDB handle the rest.

Usually, you will access, store and remove data from DynamoDB using Lambda functions. When the request reaches your Lambda function from API Gateway, here is where you can access to DynamoDB database and make any changes that you need before returning the response.

4. Cognito

AWS Cognito handles the authentication. It lets you add user sign-up, sign-in, and access control to your web and mobile apps. Amazon Cognito supports sign-in with social identity providers, such as Apple, Facebook, Google, and Amazon.

Moreover, Amazon Cognito supports multi-factor authentication and encryption of data-at-rest and in-transit.

It connects to your frontend service and by default, you have 2 options to authenticate using Cognito

  • User Pools — complete auth solution that have no authentication at all
  • Federated Identities — allows you to connect 3rd party providers like Apple, Facebook, Google, and Amazon

When users sign up/sign in it creates a user and stores 3 tokens on the client-side

  • identity token — used to authenticate requests on the backend side
  • access token — used to authenticate users
  • refresh token — used to create a new identity and access token

5. S3

Amazon S3 can be used to store data for a range of use cases, such as websites and mobile applications.

You can use Amazon S3 to host a static website. On a static website, individual web pages include static content. They might also contain client-side scripts.

By contrast, a dynamic website relies on server-side processing, including server-side scripts. Amazon S3 does not support server-side scripting.

6. CloudFront

There is one thing you can optimize in your frontend application. You can use CloudFront to optimize the way your page is distributed.

Let’s have a look at the map. All the dots you see here are CDNs (edge locations) owned by Amazon. It uses them to cache files (static website files for example).

For instance, if your main files are located in the S3 bucket in Europe, but your user is visiting the website from the US. As you can see some CDNs are nearer than your main S3 bucket. And that is exactly what CloudFront does, it copies your static files and stores them in all the CDNs. Therefore, if the user now visits your website he will automatically be redirected to the nearest location.

7. Route 53

Now that you uploaded your files to the S3 bucket, you need a domain to access the website. Turns out, AWS also has a service for that — Route 53.

Route 53 is an AWS domain name service, you can buy and manage domains using this service. Here you just configure that if your user visits example.com Route 53 translates that domain to IP and it behind the scenes uses that IP to access your S3 distribution.

Summary

Cloud providers like AWS provide building blocks, complete set of services (highly durable storage, low-cost compute, high-performance databases, management tools, and more) that are designed to work together to build scalable applications. All this is available without up-front cost, and you pay for only what you use. These services help organizations to move faster with lower costs. You now can dive deep into each of the services and implement it for yourself.

Resources

https://docs.aws.amazon.com/,

https://aws.amazon.com/products/developer-tools/?nc2=h_ql_prod_dt_dt,

https://docs.aws.amazon.com/cloudfront/index.html?nc2=h_ql_doc_cf,

https://docs.aws.amazon.com/s3/index.html?nc2=h_ql_doc_s3,

https://aws.amazon.com/s3/,

https://aws.amazon.com/cloudfront/,

https://aws.amazon.com/route53/,

https://aws.amazon.com/api-gateway/,

https://aws.amazon.com/lambda/,

https://aws.amazon.com/dynamodb/,

https://aws.amazon.com/cognito,

--

--