AWS SQS
Message Queue

Pull-based message queuing with long polling and at-least-once delivery.

AWS SNS
Pub/Sub Topics

Push-based notifications to HTTP/S, Lambda, email, or SQS subscribers.

Google Pub/Sub
GCP Service

Unified message delivery supporting both push and pull subscriptions.

Setup & Authentication

AWS SQS Setup

# Install AWS CLI (Ubuntu)
sudo apt update && sudo apt install awscli -y

# Configure credentials
aws configure
# Verify identity
aws sts get-caller-identity
// npm i @aws-sdk/client-sqs
const { SQSClient } = require("@aws-sdk/client-sqs");
const client = new SQSClient({ 
  region: 'ap-south-1' 
});
import boto3
sqs = boto3.client('sqs', 
  region_name='ap-south-1')

AWS SNS Setup

# Same AWS CLI config
aws --version
aws configure

# Quick SNS verify
aws sns list-topics
// npm i @aws-sdk/client-sns
const { SNSClient } = require('@aws-sdk/client-sns');
const sns = new SNSClient({ 
  region: 'ap-south-1' 
});
import boto3
sns = boto3.client('sns', 
  region_name='ap-south-1')

GCP Pub/Sub Setup

# Install gcloud SDK then:
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
gcloud pubsub topics list
// npm i @google-cloud/pubsub
const { PubSub } = require('@google-cloud/pubsub');
const pubsub = new PubSub({ 
  projectId: 'YOUR_PROJECT_ID' 
});
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
subscriber = pubsub_v1.SubscriberClient()
Create Queue / Topic

AWS SQS

# Create standard queue
aws sqs create-queue --queue-name my-queue
# returns QueueUrl
const { CreateQueueCommand } = require('@aws-sdk/client-sqs');
await client.send(new CreateQueueCommand({ 
  QueueName: 'my-queue' 
}));
response = sqs.create_queue(QueueName='my-queue')
queue_url = response['QueueUrl']

AWS SNS

aws sns create-topic --name my-topic
# returns TopicArn
const { CreateTopicCommand } = require('@aws-sdk/client-sns');
await sns.send(new CreateTopicCommand({ 
  Name: 'my-topic' 
}));
response = sns.create_topic(Name='my-topic')
topic_arn = response['TopicArn']

GCP Pub/Sub

gcloud pubsub topics create my-topic
const [topic] = await pubsub.createTopic('my-topic');
from google.cloud import pubsub_v1
publisher.create_topic(request={
  "name": publisher.topic_path("PROJECT_ID","my-topic")
})
Publish / Send Message

AWS SQS Send

aws sqs send-message \
  --queue-url QUEUE_URL \
  --message-body "hello"
const { SendMessageCommand } = require('@aws-sdk/client-sqs');
await client.send(new SendMessageCommand({ 
  QueueUrl: QUEUE_URL, 
  MessageBody: 'hello' 
}));
sqs.send_message(
  QueueUrl=QUEUE_URL, 
  MessageBody='hello'
)

AWS SNS Publish

aws sns publish \
  --topic-arn TOPIC_ARN \
  --message "hi subscribers"
const { PublishCommand } = require('@aws-sdk/client-sns');
await sns.send(new PublishCommand({ 
  TopicArn: TOPIC_ARN, 
  Message: 'hi' 
}));
sns.publish(
  TopicArn=TOPIC_ARN, 
  Message='hi'
)

Pub/Sub Publish

gcloud pubsub topics publish my-topic \
  --message "hello"
const dataBuffer = Buffer.from('hello');
await pubsub.topic('my-topic').publish(dataBuffer);
future = publisher.publish(
  publisher.topic_path('PROJECT_ID','my-topic'), 
  b'hello'
)
message_id = future.result()
Subscribe / Consume Messages

AWS SQS Receive

aws sqs receive-message \
  --queue-url QUEUE_URL \
  --wait-time-seconds 10
const { ReceiveMessageCommand } = require('@aws-sdk/client-sqs');
const msgs = await client.send(new 
  ReceiveMessageCommand({ 
    QueueUrl: QUEUE_URL 
  }));
resp = sqs.receive_message(
  QueueUrl=QUEUE_URL, 
  WaitTimeSeconds=10
)

AWS SNS Subscribe

# Email subscription
aws sns subscribe \
  --topic-arn TOPIC_ARN \
  --protocol email \
  --notification-endpoint you@example.com
const { SubscribeCommand } = require('@aws-sdk/client-sns');
await sns.send(new SubscribeCommand({ 
  TopicArn: TOPIC_ARN, 
  Protocol: 'email' 
}));

Push-based. Use SQS for pull pattern.

Pub/Sub Subscribe

gcloud pubsub subscriptions create my-sub \
  --topic=my-topic
gcloud pubsub subscriptions pull my-sub \
  --auto-ack --limit=10
const subscription = pubsub.subscription('my-sub');
const [messages] = await subscription.pull({ 
  maxMessages: 5 
});
messages.forEach(m => m.ack());
def callback(message):
    print(message.data)
    message.ack()
subscriber.subscribe(path, callback)
List & Delete Operations IRREVERSIBLE
AWS SQS
CLI Commands
# List all queues
aws sqs list-queues

# List queues with prefix filter
aws sqs list-queues --queue-name-prefix "my-app"
# ⚠️ DELETE QUEUE (Destructive)
aws sqs delete-queue --queue-url QUEUE_URL

# Example with real URL
aws sqs delete-queue --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue
Node.js SDK
const { ListQueuesCommand, DeleteQueueCommand } = require('@aws-sdk/client-sqs');

// List all queues
const { QueueUrls } = await client.send(new ListQueuesCommand({}));
console.log('Available queues:', QueueUrls);

// Delete specific queue (DESTRUCTIVE)
await client.send(new DeleteQueueCommand({ 
  QueueUrl: 'https://sqs.region.amazonaws.com/account-id/queue-name' 
}));
Python (boto3)
import boto3
sqs = boto3.client('sqs')

# List queues
response = sqs.list_queues()
for queue_url in response.get('QueueUrls', []):
    print(f"Found: {queue_url}")

# ⚠️ Delete queue (DESTRUCTIVE - removes all messages)
sqs.delete_queue(QueueUrl='https://sqs.region.amazonaws.com/123456789012/my-queue')
AWS SNS
# List all topics
aws sns list-topics

# List subscriptions for a topic
aws sns list-subscriptions-by-topic --topic-arn TOPIC_ARN

# List all subscriptions
aws sns list-subscriptions
# ⚠️ DELETE TOPIC (Destructive)
aws sns delete-topic --topic-arn TOPIC_ARN

# Also delete subscriptions first (optional but recommended)
aws sns unsubscribe --subscription-arn SUBSCRIPTION_ARN
Node.js SDK
const { ListTopicsCommand, DeleteTopicCommand } = require('@aws-sdk/client-sns');

// List all topics
const { Topics } = await sns.send(new ListTopicsCommand({}));
Topics.forEach(t => console.log(t.TopicArn));

// ⚠️ Delete topic (DESTRUCTIVE)
await sns.send(new DeleteTopicCommand({ 
  TopicArn: 'arn:aws:sns:us-east-1:123456789012:my-topic' 
}));
Python (boto3)
import boto3
sns = boto3.client('sns')

# List all topics
response = sns.list_topics()
for topic in response.get('Topics', []):
    print(f"Topic: {topic['TopicArn']}")

# ⚠️ Delete topic (DESTRUCTIVE - removes topic and all subscriptions)
sns.delete_topic(TopicArn='arn:aws:sns:us-east-1:123456789012:my-topic')
Google Pub/Sub
# List all topics
gcloud pubsub topics list

# List topics with filter
gcloud pubsub topics list --filter="name:my-project"

# List all subscriptions
gcloud pubsub subscriptions list
# ⚠️ DELETE TOPIC (Destructive)
gcloud pubsub topics delete my-topic

# ⚠️ DELETE SUBSCRIPTION (Destructive)
gcloud pubsub subscriptions delete my-sub

# Skip confirmation prompt
gcloud pubsub topics delete my-topic --quiet
Node.js SDK
// List all topics
const [topics] = await pubsub.getTopics();
topics.forEach(topic => console.log(topic.name));

// List all subscriptions
const [subscriptions] = await pubsub.getSubscriptions();

// ⚠️ Delete topic (DESTRUCTIVE)
await pubsub.topic('my-topic').delete();

// ⚠️ Delete subscription (DESTRUCTIVE)
await pubsub.subscription('my-sub').delete();
Python SDK
from google.cloud import pubsub_v1

publisher = pubsub_v1.PublisherClient()
subscriber = pubsub_v1.SubscriberClient()
project_id = 'YOUR_PROJECT_ID'

# List all topics
topics = publisher.list_topics(request={'project': f'projects/{project_id}'})
for topic in topics:
    print(f"Topic: {topic.name}")

# ⚠️ Delete topic (DESTRUCTIVE)
topic_path = publisher.topic_path(project_id, 'my-topic')
publisher.delete_topic(request={'topic': topic_path})

# ⚠️ Delete subscription (DESTRUCTIVE)
sub_path = subscriber.subscription_path(project_id, 'my-sub')
subscriber.delete_subscription(request={'subscription': sub_path})
⚠️ Destructive Operations Notice
Deleting queues, topics, or subscriptions is IRREVERSIBLE. All messages, configurations, and pending data will be permanently lost. Always verify the resource name/ARN before deletion.
Architecture Patterns
Producer → SQS → Consumer(s)
Pull-based, decoupled
Publisher → SNS → (Email, HTTP, SQS)
Push fan-out
Publisher → Topic → Subscription → Subscriber
Push or pull
Pro Tip: Subscribe an SQS queue to SNS for push→pull patterns. Always use IAM roles for authentication.