Build a fast full-featured serverless app with AWS

Z Yousefi
Z Yousefi
Nov 3 · 4 min read

Below is serverless architecture of a web app using Amazon Web Services — Lambda, DynamoDB, API Gateway, S3, Cognito, CloudFront, and more.

how they all work together

Why go serverless?

What can be done faster easier and cheaper?

server management (patches, monitoring, hardware failures, etc.)

servers can be cheap, but scaling gets expensive

really fast

you don’t pay for processing time

easier to split up development between front-end and back-end

Aren’t S3, Lambda, etc. servers?

Yes, but… they’re not yours !you’re not the only one on them

Amazon does all the work for you to keep them working

Use cases

good: dynamic applications with lots of user interaction most of the content in the UI is specific to the user

bad: large applications with lots of data that would have to be loaded anything where the time to load markup, JS, and data would create a very slow UI

Now let’s briefly explain services shown above

Static Chat Application with S3

Simple Storage Service Key-Blob store Eventually consistent Extremely durable

Identity and Access Management

IAM and policies

Identity and Access Management users/groups roles policies

identity providers

user account settings

encryption keys.

AWS policies define access control for users, other AWS services and resources

What is lambda?

A Function running on AWS

Language options: Java — Python — JavaScript (Node.js)

What makes lambda serverless?

Different way to trigger lambda functions:

API Gateway, AWS IoT, Alexa Skills, Alexa Smart Home, CloudWatch Events, CloudWatch Logs, CodeCommit, Cognito Sync, DynamoDB, Kinesis, S3, SNS, Lambda API CloudFront.

Creating an API with the power of API Gateway

Each resource-method combination can be its own function with its own lifecycle

each function can have simple, tailored input ensuring API compatibility can occur without code.

You can define resources and methods API models request and response flows. JSON schema each model in its own schema document

Use DynamoDB for storage

“non SQL” or “Not only SQL” basically a key-value storage system typically not ACID extremely scalable

DynamoDB vs. S3

Optimization and Preparing for Production

Stages and deployment:

snapshots of the API public URL operational settings generated clients generated swagger Canary

CloudFront

What is a CDN? Content Delivery Network

How to serve and cache a set of URIs for the content comes from S3, Web Server, API, else.

Caching, Throttling, Define variables for the stage, and Compression Node.js at the edge

SDK generation and swagger

After defining APIs and lambda functions, client side code can be generated in preferred a language like javascript. What can be easier ?!

Add Identity to the app and Authorization using Cognito

It can be done in three way:

User Pools: Your own usernames, passwords, attributes, etc.

Federated: Leverage authentication providers

Use SSO (Google, Facebook, Amazon, etc.)

Sync: Synchronize data across devices

Adding Security policies is easy in Cognito

Password length, special characters, etc.

MFA phone and email verification

Advanced Intelligent security features

Customize messages to users

Lambda functions for user lifecycle

Remember devices

Define clients of the user pool

AWS tagging

Analytics (What are your users doing?)

Finally Let’s put it all together

JavaScript: Dynamic behavior can be provided by JavaScript running in the user’s browser. The JavaScript itself is static, though.

API: Data is written to and retrieved from an API hosted by AWS cloud provider. Specifically, AWS API Gateway.

Markup: Finally, the HTML markup ties the whole thing together. The markup is static and cacheable, so the initial page load for your users is fast.

A user comes to your site and loads static HTML, CSS, and JavaScript static parts of the page are in HTML while dynamic parts of the page are added by JavaScript JavaScript retrieve dynamic data from the API JavaScript writes data to the API JavaScript handles some aspects of navigation.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade