Home
Messaging

Deploy NATS JetStream on AWS in 5 Minutes

NATS is the high-performance messaging system for cloud-native applications. With JetStream, you get persistent messaging with exactly-once delivery, replay, and stream processing. Perfect for microservices, IoT, and real-time applications.

7 min read FlowOps Consulting

What's Included

  • NATS Server with JetStream enabled
  • Persistent message storage
  • TLS encryption
  • Authentication enabled
  • Monitoring endpoints
  • Cluster-ready configuration
  • Separate data volume

Step-by-Step Guide

1

Launch the AMI

Find "NATS JetStream FlowOps" on AWS Marketplace and launch.

# Recommended instance types: # t3.medium (4GB) - Development # m5.large (8GB) - Production # m5.xlarge (16GB) - High throughput # NATS is incredibly lightweight!
2

Connect to NATS

Get credentials and test the connection.

ssh -i your-key.pem ubuntu@your-instance-ip sudo cat /opt/flowops/credentials.txt # NATS endpoints: # Client: nats://your-ip:4222 # Monitoring: http://your-ip:8222 # Test with nats CLI nats server info
3

Create a Stream

Set up JetStream for persistent messaging.

# Using NATS CLI nats stream add ORDERS \ --subjects "orders.*" \ --retention limits \ --max-msgs 1000000 \ --max-bytes 1GB \ --max-age 24h # Create a consumer nats consumer add ORDERS order-processor \ --filter "orders.created" \ --ack explicit \ --deliver all \ --replay instant # View stream info nats stream info ORDERS
4

Publish and Subscribe (Python)

Use NATS in your application with the Python client.

# pip install nats-py import asyncio import nats from nats.js.api import StreamConfig async def main(): # Connect to NATS nc = await nats.connect( servers=["nats://your-instance-ip:4222"], user="user", password="your-password" ) js = nc.jetstream() # Publish messages for i in range(10): await js.publish( "orders.created", f'{{"order_id": "ORDER-{i}", "amount": {i * 10}}}'.encode() ) print(f"Published order {i}") # Subscribe and process sub = await js.pull_subscribe("orders.created", "order-processor") while True: try: msgs = await sub.fetch(10, timeout=5) for msg in msgs: print(f"Received: {msg.data.decode()}") await msg.ack() except asyncio.TimeoutError: break await nc.close() asyncio.run(main())

Comparison

FeatureNATS JetStreamKafkaRabbitMQ
LatencySub-msLow msLow ms
ComplexitySimpleComplexMedium
PersistenceJetStreamYesYes
Resource UsageVery lightHeavyMedium
ClusteringBuilt-inZooKeeper/KRaftErlang

Use Cases

  • Microservices communication
  • IoT device messaging
  • Real-time notifications
  • Event sourcing
  • Log aggregation
  • Command and control systems

Pricing

Our AMIs are available on AWS Marketplace with simple hourly pricing:

Need Help?

Our UK-based support team is here to help you get the most out of your deployment. Email us at support@flowopsconsulting.co.uk for any questions.

Ready to Get Started?

Deploy in 5 minutes on AWS Marketplace

View on AWS Marketplace

Comments