Skip to content

AWS Services – ECS, Fargate, Lambda, S3, SNS, SQS, ELB

Published: at 04:07 PM (6 min read)

AWS Services – ECS, Fargate, Lambda, S3, SNS, SQS, ELB

Container Orchestration

Container orchestration is the automation of everything required to manage lifecycle of containers.

ECS

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service that allows you to deploy, manage, and scale containerized applications.

This is the brain (the orchestrator) that decides which containers run where and Fargate is the muscle (the compute) that actually provides the CPU and memory.

Relationship between ECS and Fargate

ECS and Fargate workflow

  1. You tell ECS “I want to run 3 copies of my Web app”.
  2. ECS looks at your configuration and sees you chosen Fargate.
  3. ECS calls Fargate and says “Hey, give me enough compute power to run these 3 container”.
  4. Fargate instantly provisions the exact CPU and RAM needed.
  5. ECS places your container onto that “invisible” Fargate power and monitors them.

Fargate

Fargate is the serverless compute engine. In old days, to run a container you would require a whole server, maintain it but with Fargate, the server is “invisible”. You don’t manage any hardware or operation systems. You simple hand over your container and say “I need to run this with this much power” and it will just work.

ELB (Elastic Load Balancer)

ELB is a load balancing service which comes in three variants:

Application load balancer

This is a proper reverse proxy which sits between server and internet. This is Application layer (Layer 7) balancer.

When you connect to ALB, the connection actually terminates at the balancer. The ALB then opens your HTTP request, looks at the headers, the cookies, and the URL path (e.g. /images vs /login)

Network load balancer

They are load balancer, but work by routing network packets rather than by proxying HTTP request. Its Transport layer (layer 4) balancer. The NLB is like a high speed railway switch. As the packets fly through lightning speed, the NLB just flicks a switch to send them to server A or server B.

It doesn’t terminate the connection, it just changes the destination on the packet and passes it through.

Lambda

This is a code runner. You upload some code and aws runs it for you.

While ec2 gives you operating system, file system, access to the server’s hardware etc. lambda abstracts away everything and gives you a function interface that lets you run code in the cloud.

Cons of using lambda function

When to use lambda function?

When your code is small and rarely changes and you need to do something in responsive to something that happens in your AWS account. This can also define this in CloudFormation template so that it actually becomes part of the infrastructure.

S3

Its a service by aws to upload things.

Object storage in s3

Why was object storage needed ?

Because traditional method of storing files wasn’t possible with billions of data. Suppose you have 3 - 10 files, then navigating the tree of folders won’t be a problem but what if its in billions ?

Introduction of object

Object is a self-contained unit in object storage, which has 3 parts:

Commands

Create bucket

aws s3 mb s3://uploads-bucket

Here, mb means make bucket.
s3://uploads-bucket(bucket name) this is the URI for bucket.

SNS (Simple Notification Service)

SNS or simple notification system is used for broadcasting. It uses pub/sub (publisher / subscriber) model. When a message hits a SNS Topic, SNS immediately pushes it to all subscribers (Email, SMS, Lamda or SQS).

Topic
Broadcasting channel. A logical access point where publishers sends messages and subscriber access those messages.

Without topic:
Order service must call:

This causes tight coupling.

And with SNS:
Order service -> topic only

This is loosely coupled, scalable, event-driven.

SQS vs SNS

SQS is pull service whereas SNS is push service.
In pull service producer directly sends message without consumer needing to ask while in push service consumer asks for the message.

SQS (Simple Queue Service)

It is a highly durable queue in the cloud. You put messages in one end and from another end its consumed. The messages are consumed in almost first-in-first-out order, but the ordering is not strict. This is because SQS queue is bunch of queue behind the scene. When we enqueue a message, it goes to a random queue, and when you poll, you poll a random queue. There’s also chance of duplicate message in SQS, so consumer should be able to handle it.

How can there be duplicate message in SQS ?

This is a distributed system, and to ensure SQS never goes down, AWS copies your messages on multiple servers. Lets understand by this scenario:

  1. Your consumer polls for message.
  2. It successfully consumes it, but you forgot to say to SQS that you have consumed it (may happen due to various reason like connection may flicker for a second)
  3. SQS sees that you haven’t acknowledged you successfully consumed the message hence it makes the message visible again.
  4. Another consumes polls the message and gains the same message.

Hence, the consumer should be idempotent, able to handle duplicate messages.

Key features of SQS


Previous Post
Understanding Prisma Migrations
Next Post
Basic server setup with express