DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on • Edited on

Part 1: Decoupled Architecture

Students will SEE messages moving.


🎯 LAB: Event-Driven Image Processing Architecture

What Students Will Build

User → ALB → EC2 (Web Tier) → S3
EC2 publishes event → SNS → SQS
Worker EC2 reads SQS → processes file → stores result in S3


🌐 Final Architecture

Image

Image

Image

Image


🟢 PHASE 1 — Create S3 Bucket

Step 1 — Open S3

  1. AWS Console → search S3
  2. Click Create bucket

Step 2 — Configure

Bucket name:

student-upload-bucket-<yourname>
Enter fullscreen mode Exit fullscreen mode

Region:

us-east-2
Enter fullscreen mode Exit fullscreen mode

Uncheck:

Block all public access
Enter fullscreen mode Exit fullscreen mode

Check confirmation box.

Click:

Create bucket
Enter fullscreen mode Exit fullscreen mode

🟢 PHASE 2 — Create SNS Topic

  1. Search SNS
  2. Click Create topic
  3. Type: Standard
  4. Name:
file-upload-topic
Enter fullscreen mode Exit fullscreen mode
  1. Click Create topic
  2. Copy ARN → save it

🟢 PHASE 3 — Create SQS Queue

  1. Search SQS
  2. Click Create queue
  3. Type: Standard
  4. Name:
file-processing-queue
Enter fullscreen mode Exit fullscreen mode
  1. Click Create queue
  2. Copy ARN

🟢 PHASE 4 — Subscribe SQS to SNS

  1. Go back to SNS
  2. Click topic: file-upload-topic
  3. Click Create subscription
  4. Protocol: Amazon SQS
  5. Endpoint: paste SQS ARN
  6. Click Create subscription

🟢 PHASE 5 — Allow SNS → SQS

  1. Go to SQS → file-processing-queue
  2. Click Edit access policy
  3. Choose Advanced
  4. Paste:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Allow-SNS",
      "Effect": "Allow",
      "Principal": { "Service": "sns.amazonaws.com" },
      "Action": "sqs:SendMessage",
      "Resource": "YOUR_SQS_ARN",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "YOUR_SNS_ARN"
        }
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Replace ARNs.

Save.


🟢 PHASE 6 — Create Web EC2 (Publisher)

  1. Go to EC2
  2. Click Launch Instance

Name:

web-server
Enter fullscreen mode Exit fullscreen mode

AMI:

Amazon Linux 2
Enter fullscreen mode Exit fullscreen mode

Instance type:

t2.micro
Enter fullscreen mode Exit fullscreen mode

Create key pair.

Security Group:
Allow:

  • HTTP (80)
  • SSH (22)

Click Launch.


🟢 PHASE 7 — Install Web App

SSH into instance:

sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo yum install aws-cli -y
Enter fullscreen mode Exit fullscreen mode

Create upload page:

sudo nano /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Paste:

<h1>Upload Simulation</h1>
<form method="POST" action="/upload">
<input type="text" name="filename" placeholder="Enter file name">
<button type="submit">Upload</button>
</form>
Enter fullscreen mode Exit fullscreen mode

Save.


🟢 PHASE 8 — Install Python Publisher Script

sudo yum install python3 -y
nano publisher.py
Enter fullscreen mode Exit fullscreen mode

Paste:

import boto3
sns = boto3.client('sns', region_name='us-east-2')

response = sns.publish(
    TopicArn='YOUR_TOPIC_ARN',
    Message='File uploaded: test-image.png'
)
print("Message sent")
Enter fullscreen mode Exit fullscreen mode

Replace ARN.

Run:

python3 publisher.py
Enter fullscreen mode Exit fullscreen mode

It will send event to SNS.


🟢 PHASE 9 — Create Worker EC2

Launch second instance:

Name:

worker-server
Enter fullscreen mode Exit fullscreen mode

Install Python + AWS CLI.


🟢 PHASE 10 — Worker Script (Consumer)

On worker:

nano worker.py
Enter fullscreen mode Exit fullscreen mode

Paste:

import boto3
import time

sqs = boto3.client('sqs', region_name='us-east-2')

queue_url = 'YOUR_QUEUE_URL'

while True:
    messages = sqs.receive_message(
        QueueUrl=queue_url,
        MaxNumberOfMessages=1,
        WaitTimeSeconds=5
    )

    if 'Messages' in messages:
        for message in messages['Messages']:
            print("Processing:", message['Body'])
            sqs.delete_message(
                QueueUrl=queue_url,
                ReceiptHandle=message['ReceiptHandle']
            )
    time.sleep(3)
Enter fullscreen mode Exit fullscreen mode

Replace Queue URL.

Run:

python3 worker.py
Enter fullscreen mode Exit fullscreen mode

Now it polls continuously.


🟢 PHASE 11 — Test Flow

  1. Run publisher on web server.
  2. Worker prints:
Processing: File uploaded: test-image.png
Enter fullscreen mode Exit fullscreen mode

Students will SEE event-driven processing live.


🟢 OPTIONAL — Add ALB + ASG

Create:

  • Target Group
  • Launch Template
  • Auto Scaling Group
  • Application Load Balancer

Attach web-server template to ASG.

Now traffic hits ALB.


🎓 What Students Learn

• Decoupling architecture
• Event-driven systems
• Async processing
• Worker scaling
• Production DevOps pattern

Top comments (0)