RDS & S3

๐Ÿ”ฅ Vibe Prompt

"Provision RDS Postgres with Multi-AZ, automated backups. S3 bucket with versioning, lifecycle policy."

RDS PostgreSQL

resource "aws_db_instance" "postgres" {
  identifier     = "app-db"
  engine         = "postgres"
  engine_version = "16.3"
  instance_class = "db.t3.medium"
  
  db_name  = "myapp"
  username = var.db_username
  password = var.db_password
  
  allocated_storage     = 100
  storage_type          = "gp3"
  backup_retention_period = 30
  backup_window         = "03:00-04:00"
  maintenance_window    = "sun:04:00-sun:05:00"
  
  multi_az = true
  
  vpc_security_group_ids = [aws_security_group.db.id]
  db_subnet_group_name   = aws_db_subnet_group.main.name
  
  deletion_protection = true
  skip_final_snapshot = false
}

S3 Bucket

resource "aws_s3_bucket" "assets" {
  bucket = "myapp-assets-prod"
}

resource "aws_s3_bucket_versioning" "assets" {
  bucket = aws_s3_bucket.assets.id
  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_lifecycle_configuration" "assets" {
  bucket = aws_s3_bucket.assets.id
  rule {
    id = "expire-old-versions"
    status = "Enabled"
    noncurrent_version_expiration {
      noncurrent_days = 90
    }
  }
}

resource "aws_s3_bucket_public_access_block" "assets" {
  bucket = aws_s3_bucket.assets.id
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

RDS vs S3

| Feature | RDS | S3 | |---------|-----|-----| | Data type | Structured (SQL) | Objects (files) | | Max size | 16 TB per instance | Unlimited | | Backup | Automated (PITR) | Versioning + Lifecycle | | HA | Multi-AZ | 11 9s durability | | Access | VPC only | HTTP(S) + IAM |

Best Practices

  • RDS: Enable deletion protection, automated backups
  • S3: Block public access, enable versioning, encrypt with KMS

Chapter Summary

  • Understand core concepts and principles
  • Master implementation methods and techniques
  • Familiar with common issues and solutions
  • Able to apply in real projects

Further Reading

RDS (Relational Database Service)

RDS Features

| Feature | Description | |---------|-------------| | Managed databases | Automated backups, patching, replication | | Multi-AZ | Synchronous standby in another AZ for high availability | | Read replicas | Asynchronous replication for read scaling | | Automated backups | Daily snapshots with transaction logs (point-in-time recovery) | | Encryption | At-rest and in-transit encryption | | Monitoring | CloudWatch metrics, Enhanced Monitoring, Performance Insights |

Supported Database Engines

| Engine | Use Case | |--------|----------| | PostgreSQL | Open-source, advanced features | | MySQL | Popular, compatible with many apps | | MariaDB | MySQL-compatible, community-driven | | SQL Server | Enterprise .NET applications | | Oracle | Legacy enterprise applications | | Aurora | AWS-native, 5x faster than MySQL, 3x faster than PostgreSQL |

RDS vs DynamoDB

| Aspect | RDS | DynamoDB | |--------|-----|----------| | Type | Relational (SQL) | NoSQL (key-value/document) | | Schema | Fixed schema | Schemaless | | Queries | Complex joins, aggregations | Simple key lookups, limited filtering | | Scaling | Vertical (bigger instances) | Horizontal (auto-scaling) | | Pricing | Pay per hour (provisioned) | Pay per request (on-demand) | | Best for | Complex data relationships | High-volume, simple access patterns |

S3 (Simple Storage Service)

S3 is object storage for any type of file. It is highly durable (99.999999999% durability), highly available, and infinitely scalable.

S3 Storage Classes

| Class | Durability | Availability | Retrieval | Use Case | |-------|-----------|-------------|-----------|----------| | Standard | 99.999999999% | 99.99% | Instant | Frequently accessed data | | Intelligent-Tiering | 99.999999999% | 99.99% | Instant | Unknown access patterns | | Standard-IA | 99.999999999% | 99.9% | Instant | Infrequent access, long-lived | | One Zone-IA | 99.999999999% | 99.5% | Instant | Recreatable data | | Glacier | 99.999999999% | 99.99% | Minutes to hours | Archival data | | Glacier Deep Archive | 99.999999999% | 99.99% | 12 hours | Long-term archival |

S3 Features

| Feature | Description | |---------|-------------| | Versioning | Keep multiple versions of objects | | Lifecycle rules | Automatically transition or expire objects | | Static website hosting | Host HTML/CSS/JS websites | | Bucket policies | Resource-based access control | | CORS | Configure cross-origin access | | Encryption | SSE-S3, SSE-KMS, SSE-C | | Event notifications | SNS, SQS, Lambda on bucket events | | Transfer Acceleration | Fast uploads over long distances |

Summary

RDS provides managed relational databases (PostgreSQL, MySQL, Aurora) with automated backups, multi-AZ, and read replicas. S3 provides infinitely scalable object storage with multiple storage classes for different access patterns.

Key takeaways:

  • RDS: managed relational database, supports 6 engines |
  • Multi-AZ: high availability with automatic failover |
  • Read replicas: scale read performance |
  • Aurora: AWS-native, 5x faster than MySQL |
  • S3: 99.999999999% durability, 11 9's |
  • Storage classes: Standard โ†’ IA โ†’ Glacier โ†’ Deep Archive |
  • Lifecycle rules automate tier transitions |
  • Versioning protects against accidental deletion |
  • Bucket policies control access at the bucket level |

What's Next: CloudFront & WAF

The next chapter covers CloudFront (CDN) and WAF (Web Application Firewall) โ€” global content delivery and security protection.

Common RDS Tasks

| Task | AWS CLI | |------|---------| | Create PostgreSQL instance | aws rds create-db-instance --engine postgres --db-instance-class db.t3.micro ... | | Take manual snapshot | aws rds create-db-snapshot --db-instance-identifier mydb --db-snapshot-identifier mydb-snap | | Restore from snapshot | aws rds restore-db-instance-from-db-snapshot --db-instance-identifier mydb-restored ... | | Modify instance | aws rds modify-db-instance --db-instance-identifier mydb --db-instance-class db.t3.small | | Create read replica | aws rds create-db-instance-read-replica --db-instance-identifier mydb-read ... | | Failover to standby | aws rds reboot-db-instance --db-instance-identifier mydb --force-failover |

Common S3 Tasks

| Task | AWS CLI | |------|---------| | Create bucket | aws s3 mb s3://my-bucket --region us-east-1 | | Upload file | aws s3 cp file.txt s3://my-bucket/ | | Sync directory | aws s3 sync ./dist s3://my-bucket/ --delete | | List objects | aws s3 ls s3://my-bucket/ --recursive | | Set lifecycle rule | aws s3api put-bucket-lifecycle-configuration --bucket my-bucket ... | | Enable versioning | aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration Status=Enabled | | Set bucket policy | aws s3api put-bucket-policy --bucket my-bucket --policy file://policy.json |

Summary

RDS and S3 are the two most commonly used AWS storage services. RDS provides managed relational databases with high availability. S3 provides infinitely scalable object storage for files, backups, and static assets.

Key takeaways:

  • RDS: managed SQL databases (PostgreSQL, MySQL, Aurora) |
  • Multi-AZ: automatic failover for high availability |
  • Read replicas: scale read traffic |
  • S3: 11 9's durability, infinite scalability |
  • Storage classes: Standard โ†’ IA โ†’ Glacier โ†’ Deep Archive |
  • Lifecycle rules automate storage tier transitions |
  • Versioning prevents accidental deletion |
  • Bucket policies and IAM control access |

What's Next: CloudFront & WAF

The next chapter covers CloudFront (CDN) and WAF (Web Application Firewall).

Member Exclusive Free Tutorial

This chapter is free exclusive content for registered members! Please login or register to unlock immediately.

Login / Register Now