Claude Skill

rds

AWS RDS relational database service for managed databases. Use when provisioning databases, configuring backups, managing replicas, troubleshooting connectivity, or optimizing performance.

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Virus-scanned Reviewed automatically before listing.

Full trust report

Download itsmostafa-aws-agent-skills-skills_rds-e786d25.zip · 5 KB
Part of itsmostafa/aws-agent-skills — 17 skills

Install

skills CLI npx skills add https://github.com/itsmostafa/aws-agent-skills/tree/main/skills/rds
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install itsmostafa-aws-agent-skills@llmmart
Git git clone https://github.com/itsmostafa/aws-agent-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole itsmostafa/aws-agent-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

AWS RDS

Amazon Relational Database Service (RDS) provides managed relational databases including MySQL, PostgreSQL, MariaDB, Oracle, SQL Server, and Aurora. RDS handles provisioning, patching, backups, and failover.

Table of Contents

Core Concepts

DB Instance Classes

Category Example Use Case
Standard db.m6g.large General purpose
Memory Optimized db.r6g.large High memory workloads
Burstable db.t3.medium Variable workloads, dev/test

Storage Types

Type IOPS Use Case
gp3 3,000-16,000 Most workloads
io1/io2 Up to 256,000 High-performance OLTP
magnetic N/A Legacy, avoid

Multi-AZ Deployments

  • Multi-AZ Instance: Synchronous standby in different AZ
  • Multi-AZ Cluster: One writer, two reader instances (Aurora-like)

Read Replicas

Asynchronous copies for read scaling. Can be cross-region.

Common Patterns

Create a PostgreSQL Instance

AWS CLI:

# Create DB subnet group
aws rds create-db-subnet-group \
  --db-subnet-group-name my-db-subnet-group \
  --db-subnet-group-description "Private subnets for RDS" \
  --subnet-ids subnet-12345678 subnet-87654321

# Create security group (allow PostgreSQL from app)
aws ec2 create-security-group \
  --group-name rds-postgres-sg \
  --description "RDS PostgreSQL access" \
  --vpc-id vpc-12345678

aws ec2 authorize-security-group-ingress \
  --group-id sg-rds12345 \
  --protocol tcp \
  --port 5432 \
  --source-group sg-app12345

# Create RDS instance
aws rds create-db-instance \
  --db-instance-identifier my-postgres \
  --db-instance-class db.t3.medium \
  --engine postgres \
  --engine-version 16.1 \
  --master-username admin \
  --master-user-password 'SecurePassword123!' \
  --allocated-storage 100 \
  --storage-type gp3 \
  --db-subnet-group-name my-db-subnet-group \
  --vpc-security-group-ids sg-rds12345 \
  --multi-az \
  --backup-retention-period 7 \
  --storage-encrypted \
  --no-publicly-accessible

boto3:

import boto3

rds = boto3.client('rds')

response = rds.create_db_instance(
    DBInstanceIdentifier='my-postgres',
    DBInstanceClass='db.t3.medium',
    Engine='postgres',
    EngineVersion='16.1',
    MasterUsername='admin',
    MasterUserPassword='SecurePassword123!',
    AllocatedStorage=100,
    StorageType='gp3',
    DBSubnetGroupName='my-db-subnet-group',
    VpcSecurityGroupIds=['sg-rds12345'],
    MultiAZ=True,
    BackupRetentionPeriod=7,
    StorageEncrypted=True,
    PubliclyAccessible=False
)

Create Read Replica

aws rds create-db-instance-read-replica \
  --db-instance-identifier my-postgres-replica \
  --source-db-instance-identifier my-postgres \
  --db-instance-class db.t3.medium \
  --availability-zone us-east-1b

Take a Snapshot

aws rds create-db-snapshot \
  --db-snapshot-identifier my-postgres-snapshot-2024-01-15 \
  --db-instance-identifier my-postgres

Restore from Snapshot

aws rds restore-db-instance-from-db-snapshot \
  --db-instance-identifier my-postgres-restored \
  --db-snapshot-identifier my-postgres-snapshot-2024-01-15 \
  --db-instance-class db.t3.medium \
  --db-subnet-group-name my-db-subnet-group \
  --vpc-security-group-ids sg-rds12345

Point-in-Time Recovery

aws rds restore-db-instance-to-point-in-time \
  --source-db-instance-identifier my-postgres \
  --target-db-instance-identifier my-postgres-pitr \
  --restore-time 2024-01-15T10:30:00Z \
  --db-instance-class db.t3.medium

Modify Instance

# Change instance class (with downtime)
aws rds modify-db-instance \
  --db-instance-identifier my-postgres \
  --db-instance-class db.m6g.large \
  --apply-immediately

# Scale storage (no downtime)
aws rds modify-db-instance \
  --db-instance-identifier my-postgres \
  --allocated-storage 200 \
  --apply-immediately

Connect with IAM Authentication

import boto3
import psycopg2

rds = boto3.client('rds')

# Generate auth token
token = rds.generate_db_auth_token(
    DBHostname='my-postgres.abc123.us-east-1.rds.amazonaws.com',
    Port=5432,
    DBUsername='iam_user',
    Region='us-east-1'
)

# Connect
conn = psycopg2.connect(
    host='my-postgres.abc123.us-east-1.rds.amazonaws.com',
    port=5432,
    database='mydb',
    user='iam_user',
    password=token,
    sslmode='require'
)

CLI Reference

Instance Management

Command Description
aws rds create-db-instance Create instance
aws rds describe-db-instances List instances
aws rds modify-db-instance Modify settings
aws rds delete-db-instance Delete instance
aws rds reboot-db-instance Reboot instance
aws rds start-db-instance Start stopped instance
aws rds stop-db-instance Stop instance

Backups

Command Description
aws rds create-db-snapshot Manual snapshot
aws rds describe-db-snapshots List snapshots
aws rds restore-db-instance-from-db-snapshot Restore from snapshot
aws rds restore-db-instance-to-point-in-time Point-in-time restore
aws rds copy-db-snapshot Copy snapshot

Replicas

Command Description
aws rds create-db-instance-read-replica Create read replica
aws rds promote-read-replica Promote to standalone

Best Practices

Security

  • Never make publicly accessible — use VPC and security groups
  • Enable encryption at rest (KMS) and in transit (SSL)
  • Use IAM authentication for application access
  • Store credentials in Secrets Manager with rotation
  • Use parameter groups to enforce SSL
# Enforce SSL in PostgreSQL
aws rds modify-db-parameter-group \
  --db-parameter-group-name my-pg-params \
  --parameters "ParameterName=rds.force_ssl,ParameterValue=1,ApplyMethod=pending-reboot"

Performance

  • Right-size instances — monitor CPU, memory, IOPS
  • Use gp3 for cost-effective performance
  • Enable Performance Insights for query analysis
  • Use read replicas for read scaling
  • Optimize queries — check slow query log

High Availability

  • Enable Multi-AZ for production
  • Use Aurora for mission-critical workloads
  • Configure appropriate backup retention
  • Test failover periodically
  • Monitor replication lag for replicas

Cost Optimization

  • Use Reserved Instances for steady-state workloads
  • Stop dev/test instances when not in use
  • Delete old snapshots regularly
  • Right-size instance classes

Troubleshooting

Cannot Connect

Causes:

  1. Security group not allowing access
  2. Instance not in VPC subnet
  3. SSL required but not used
  4. Wrong endpoint/port

Debug:

# Check security group
aws ec2 describe-security-groups --group-ids sg-rds12345

# Check instance status
aws rds describe-db-instances \
  --db-instance-identifier my-postgres \
  --query "DBInstances[0].{Status:DBInstanceStatus,Endpoint:Endpoint}"

# Test connectivity from EC2
nc -zv my-postgres.abc123.us-east-1.rds.amazonaws.com 5432

High CPU/Memory

Debug:

# Enable Enhanced Monitoring
aws rds modify-db-instance \
  --db-instance-identifier my-postgres \
  --monitoring-interval 60 \
  --monitoring-role-arn arn:aws:iam::123456789012:role/rds-monitoring-role

# Enable Performance Insights
aws rds modify-db-instance \
  --db-instance-identifier my-postgres \
  --enable-performance-insights \
  --performance-insights-retention-period 7

Solutions:

  • Scale up instance class
  • Optimize slow queries
  • Add read replicas
  • Check for locking/blocking

Storage Full

Symptom: Instance becomes unavailable

Prevention:

# Enable storage autoscaling
aws rds modify-db-instance \
  --db-instance-identifier my-postgres \
  --max-allocated-storage 500

# Set CloudWatch alarm
aws cloudwatch put-metric-alarm \
  --alarm-name "RDS-Storage-Low" \
  --metric-name FreeStorageSpace \
  --namespace AWS/RDS \
  --dimensions Name=DBInstanceIdentifier,Value=my-postgres \
  --statistic Average \
  --period 300 \
  --threshold 10000000000 \
  --comparison-operator LessThanThreshold \
  --evaluation-periods 2 \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:alerts

Replication Lag

Monitor:

aws cloudwatch get-metric-statistics \
  --namespace AWS/RDS \
  --metric-name ReplicaLag \
  --dimensions Name=DBInstanceIdentifier,Value=my-postgres-replica \
  --start-time $(date -d '1 hour ago' -u +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 60 \
  --statistics Average

Causes:

  • Replica instance too small
  • Heavy write load
  • Network issues
  • Long-running queries on replica

References

Files (aws-agent-skills)
  • administration.md 7.9 KB
    # RDS Administration
    
    Database administration tasks for RDS.
    
    ## Parameter Groups
    
    ### Create Parameter Group
    
    ```bash
    aws rds create-db-parameter-group \
      --db-parameter-group-name my-postgres-params \
      --db-parameter-group-family postgres16 \
      --description "Custom PostgreSQL parameters"
    ```
    
    ### Common PostgreSQL Parameters
    
    ```bash
    # Set parameters
    aws rds modify-db-parameter-group \
      --db-parameter-group-name my-postgres-params \
      --parameters \
        "ParameterName=max_connections,ParameterValue=200,ApplyMethod=pending-reboot" \
        "ParameterName=shared_buffers,ParameterValue={DBInstanceClassMemory/4},ApplyMethod=pending-reboot" \
        "ParameterName=work_mem,ParameterValue=65536,ApplyMethod=immediate" \
        "ParameterName=maintenance_work_mem,ParameterValue=524288,ApplyMethod=immediate" \
        "ParameterName=log_statement,ParameterValue=ddl,ApplyMethod=immediate" \
        "ParameterName=log_min_duration_statement,ParameterValue=1000,ApplyMethod=immediate"
    ```
    
    ### Common MySQL Parameters
    
    ```bash
    aws rds modify-db-parameter-group \
      --db-parameter-group-name my-mysql-params \
      --parameters \
        "ParameterName=max_connections,ParameterValue=200,ApplyMethod=pending-reboot" \
        "ParameterName=innodb_buffer_pool_size,ParameterValue={DBInstanceClassMemory*3/4},ApplyMethod=pending-reboot" \
        "ParameterName=slow_query_log,ParameterValue=1,ApplyMethod=immediate" \
        "ParameterName=long_query_time,ParameterValue=1,ApplyMethod=immediate" \
        "ParameterName=log_queries_not_using_indexes,ParameterValue=1,ApplyMethod=immediate"
    ```
    
    ### Apply Parameter Group
    
    ```bash
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --db-parameter-group-name my-postgres-params \
      --apply-immediately
    ```
    
    ## Option Groups
    
    ### Create Option Group (SQL Server, Oracle, MySQL)
    
    ```bash
    aws rds create-option-group \
      --option-group-name my-mysql-options \
      --engine-name mysql \
      --major-engine-version 8.0 \
      --option-group-description "MySQL options"
    ```
    
    ### Add Options
    
    ```bash
    # Add MySQL memcached
    aws rds add-option-to-option-group \
      --option-group-name my-mysql-options \
      --options OptionName=MEMCACHED
    
    # Add SQL Server TDE
    aws rds add-option-to-option-group \
      --option-group-name my-sqlserver-options \
      --options OptionName=TDE
    ```
    
    ## Backup Management
    
    ### Automated Backups
    
    ```bash
    # Configure backup window
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --backup-retention-period 14 \
      --preferred-backup-window "03:00-04:00"
    ```
    
    ### Manual Snapshots
    
    ```bash
    # Create snapshot
    aws rds create-db-snapshot \
      --db-snapshot-identifier my-postgres-$(date +%Y%m%d) \
      --db-instance-identifier my-postgres
    
    # Wait for completion
    aws rds wait db-snapshot-available \
      --db-snapshot-identifier my-postgres-20240115
    ```
    
    ### Copy Snapshot Cross-Region
    
    ```bash
    aws rds copy-db-snapshot \
      --source-db-snapshot-identifier arn:aws:rds:us-east-1:123456789012:snapshot:my-postgres-20240115 \
      --target-db-snapshot-identifier my-postgres-20240115 \
      --source-region us-east-1 \
      --region us-west-2 \
      --kms-key-id alias/aws/rds
    ```
    
    ### Share Snapshot
    
    ```bash
    aws rds modify-db-snapshot-attribute \
      --db-snapshot-identifier my-postgres-20240115 \
      --attribute-name restore \
      --values-to-add 111111111111
    ```
    
    ### Export to S3
    
    ```bash
    aws rds start-export-task \
      --export-task-identifier my-export-2024 \
      --source-arn arn:aws:rds:us-east-1:123456789012:snapshot:my-postgres-20240115 \
      --s3-bucket-name my-rds-exports \
      --iam-role-arn arn:aws:iam::123456789012:role/rds-s3-export-role \
      --kms-key-id alias/aws/rds
    ```
    
    ## Maintenance
    
    ### Maintenance Window
    
    ```bash
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --preferred-maintenance-window "sun:04:00-sun:05:00"
    ```
    
    ### Pending Maintenance
    
    ```bash
    # View pending maintenance
    aws rds describe-pending-maintenance-actions
    
    # Apply immediately
    aws rds apply-pending-maintenance-action \
      --resource-identifier arn:aws:rds:us-east-1:123456789012:db:my-postgres \
      --apply-action system-update \
      --opt-in-type immediate
    ```
    
    ### Engine Upgrades
    
    ```bash
    # Check available versions
    aws rds describe-db-engine-versions \
      --engine postgres \
      --engine-version 15.4 \
      --query "DBEngineVersions[].ValidUpgradeTarget"
    
    # Upgrade (causes downtime)
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --engine-version 16.1 \
      --allow-major-version-upgrade \
      --apply-immediately
    ```
    
    ## Monitoring
    
    ### CloudWatch Metrics
    
    Key metrics to monitor:
    
    | Metric | Description | Alarm Threshold |
    |--------|-------------|-----------------|
    | CPUUtilization | CPU usage % | > 80% |
    | DatabaseConnections | Active connections | > 80% of max_connections |
    | FreeableMemory | Available RAM | < 256 MB |
    | FreeStorageSpace | Available storage | < 20% |
    | ReadIOPS, WriteIOPS | I/O operations | Near provisioned IOPS |
    | ReadLatency, WriteLatency | I/O latency | > 20ms |
    | DiskQueueDepth | Pending I/O requests | > 5 |
    | ReplicaLag | Replication delay | > 60 seconds |
    
    ### Enhanced Monitoring
    
    ```bash
    # Create IAM role for enhanced monitoring
    aws iam create-role \
      --role-name rds-monitoring-role \
      --assume-role-policy-document '{
        "Version": "2012-10-17",
        "Statement": [{
          "Effect": "Allow",
          "Principal": {"Service": "monitoring.rds.amazonaws.com"},
          "Action": "sts:AssumeRole"
        }]
      }'
    
    aws iam attach-role-policy \
      --role-name rds-monitoring-role \
      --policy-arn arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole
    
    # Enable on instance
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --monitoring-interval 60 \
      --monitoring-role-arn arn:aws:iam::123456789012:role/rds-monitoring-role
    ```
    
    ### Performance Insights
    
    ```bash
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --enable-performance-insights \
      --performance-insights-retention-period 7 \
      --performance-insights-kms-key-id alias/aws/rds
    ```
    
    ### CloudWatch Logs
    
    ```bash
    # Enable PostgreSQL logs
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --cloudwatch-logs-export-configuration '{
        "EnableLogTypes": ["postgresql", "upgrade"]
      }'
    
    # Enable MySQL logs
    aws rds modify-db-instance \
      --db-instance-identifier my-mysql \
      --cloudwatch-logs-export-configuration '{
        "EnableLogTypes": ["audit", "error", "general", "slowquery"]
      }'
    ```
    
    ## Secrets Manager Integration
    
    ### Create Secret with Rotation
    
    ```bash
    # Create secret
    aws secretsmanager create-secret \
      --name rds/my-postgres/admin \
      --secret-string '{"username":"admin","password":"InitialPassword123!"}'
    
    # Enable rotation
    aws secretsmanager rotate-secret \
      --secret-id rds/my-postgres/admin \
      --rotation-lambda-arn arn:aws:lambda:us-east-1:123456789012:function:SecretsManagerRDSPostgreSQLRotation \
      --rotation-rules AutomaticallyAfterDays=30
    ```
    
    ### Use Secret in Application
    
    ```python
    import boto3
    import json
    import psycopg2
    
    secrets = boto3.client('secretsmanager')
    
    def get_connection():
        secret = secrets.get_secret_value(SecretId='rds/my-postgres/admin')
        creds = json.loads(secret['SecretString'])
    
        return psycopg2.connect(
            host=creds['host'],
            port=creds['port'],
            database=creds['dbname'],
            user=creds['username'],
            password=creds['password']
        )
    ```
    
    ## Failover and Recovery
    
    ### Manual Failover (Multi-AZ)
    
    ```bash
    aws rds reboot-db-instance \
      --db-instance-identifier my-postgres \
      --force-failover
    ```
    
    ### Promote Read Replica
    
    ```bash
    aws rds promote-read-replica \
      --db-instance-identifier my-postgres-replica \
      --backup-retention-period 7
    ```
    
    ### Blue-Green Deployment
    
    ```bash
    # Create blue-green deployment
    aws rds create-blue-green-deployment \
      --blue-green-deployment-name my-bg-deployment \
      --source arn:aws:rds:us-east-1:123456789012:db:my-postgres \
      --target-engine-version 16.1
    
    # Switchover (after testing green)
    aws rds switchover-blue-green-deployment \
      --blue-green-deployment-identifier bgd-abc123
    ```
    
  • SKILL.md 9.5 KB
    ---
    name: rds
    description: AWS RDS relational database service for managed databases. Use when provisioning databases, configuring backups, managing replicas, troubleshooting connectivity, or optimizing performance.
    last_updated: "2026-01-07"
    doc_source: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/
    ---
    
    # AWS RDS
    
    Amazon Relational Database Service (RDS) provides managed relational databases including MySQL, PostgreSQL, MariaDB, Oracle, SQL Server, and Aurora. RDS handles provisioning, patching, backups, and failover.
    
    ## Table of Contents
    
    - [Core Concepts](#core-concepts)
    - [Common Patterns](#common-patterns)
    - [CLI Reference](#cli-reference)
    - [Best Practices](#best-practices)
    - [Troubleshooting](#troubleshooting)
    - [References](#references)
    
    ## Core Concepts
    
    ### DB Instance Classes
    
    | Category | Example | Use Case |
    |----------|---------|----------|
    | Standard | db.m6g.large | General purpose |
    | Memory Optimized | db.r6g.large | High memory workloads |
    | Burstable | db.t3.medium | Variable workloads, dev/test |
    
    ### Storage Types
    
    | Type | IOPS | Use Case |
    |------|------|----------|
    | gp3 | 3,000-16,000 | Most workloads |
    | io1/io2 | Up to 256,000 | High-performance OLTP |
    | magnetic | N/A | Legacy, avoid |
    
    ### Multi-AZ Deployments
    
    - **Multi-AZ Instance**: Synchronous standby in different AZ
    - **Multi-AZ Cluster**: One writer, two reader instances (Aurora-like)
    
    ### Read Replicas
    
    Asynchronous copies for read scaling. Can be cross-region.
    
    ## Common Patterns
    
    ### Create a PostgreSQL Instance
    
    **AWS CLI:**
    
    ```bash
    # Create DB subnet group
    aws rds create-db-subnet-group \
      --db-subnet-group-name my-db-subnet-group \
      --db-subnet-group-description "Private subnets for RDS" \
      --subnet-ids subnet-12345678 subnet-87654321
    
    # Create security group (allow PostgreSQL from app)
    aws ec2 create-security-group \
      --group-name rds-postgres-sg \
      --description "RDS PostgreSQL access" \
      --vpc-id vpc-12345678
    
    aws ec2 authorize-security-group-ingress \
      --group-id sg-rds12345 \
      --protocol tcp \
      --port 5432 \
      --source-group sg-app12345
    
    # Create RDS instance
    aws rds create-db-instance \
      --db-instance-identifier my-postgres \
      --db-instance-class db.t3.medium \
      --engine postgres \
      --engine-version 16.1 \
      --master-username admin \
      --master-user-password 'SecurePassword123!' \
      --allocated-storage 100 \
      --storage-type gp3 \
      --db-subnet-group-name my-db-subnet-group \
      --vpc-security-group-ids sg-rds12345 \
      --multi-az \
      --backup-retention-period 7 \
      --storage-encrypted \
      --no-publicly-accessible
    ```
    
    **boto3:**
    
    ```python
    import boto3
    
    rds = boto3.client('rds')
    
    response = rds.create_db_instance(
        DBInstanceIdentifier='my-postgres',
        DBInstanceClass='db.t3.medium',
        Engine='postgres',
        EngineVersion='16.1',
        MasterUsername='admin',
        MasterUserPassword='SecurePassword123!',
        AllocatedStorage=100,
        StorageType='gp3',
        DBSubnetGroupName='my-db-subnet-group',
        VpcSecurityGroupIds=['sg-rds12345'],
        MultiAZ=True,
        BackupRetentionPeriod=7,
        StorageEncrypted=True,
        PubliclyAccessible=False
    )
    ```
    
    ### Create Read Replica
    
    ```bash
    aws rds create-db-instance-read-replica \
      --db-instance-identifier my-postgres-replica \
      --source-db-instance-identifier my-postgres \
      --db-instance-class db.t3.medium \
      --availability-zone us-east-1b
    ```
    
    ### Take a Snapshot
    
    ```bash
    aws rds create-db-snapshot \
      --db-snapshot-identifier my-postgres-snapshot-2024-01-15 \
      --db-instance-identifier my-postgres
    ```
    
    ### Restore from Snapshot
    
    ```bash
    aws rds restore-db-instance-from-db-snapshot \
      --db-instance-identifier my-postgres-restored \
      --db-snapshot-identifier my-postgres-snapshot-2024-01-15 \
      --db-instance-class db.t3.medium \
      --db-subnet-group-name my-db-subnet-group \
      --vpc-security-group-ids sg-rds12345
    ```
    
    ### Point-in-Time Recovery
    
    ```bash
    aws rds restore-db-instance-to-point-in-time \
      --source-db-instance-identifier my-postgres \
      --target-db-instance-identifier my-postgres-pitr \
      --restore-time 2024-01-15T10:30:00Z \
      --db-instance-class db.t3.medium
    ```
    
    ### Modify Instance
    
    ```bash
    # Change instance class (with downtime)
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --db-instance-class db.m6g.large \
      --apply-immediately
    
    # Scale storage (no downtime)
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --allocated-storage 200 \
      --apply-immediately
    ```
    
    ### Connect with IAM Authentication
    
    ```python
    import boto3
    import psycopg2
    
    rds = boto3.client('rds')
    
    # Generate auth token
    token = rds.generate_db_auth_token(
        DBHostname='my-postgres.abc123.us-east-1.rds.amazonaws.com',
        Port=5432,
        DBUsername='iam_user',
        Region='us-east-1'
    )
    
    # Connect
    conn = psycopg2.connect(
        host='my-postgres.abc123.us-east-1.rds.amazonaws.com',
        port=5432,
        database='mydb',
        user='iam_user',
        password=token,
        sslmode='require'
    )
    ```
    
    ## CLI Reference
    
    ### Instance Management
    
    | Command | Description |
    |---------|-------------|
    | `aws rds create-db-instance` | Create instance |
    | `aws rds describe-db-instances` | List instances |
    | `aws rds modify-db-instance` | Modify settings |
    | `aws rds delete-db-instance` | Delete instance |
    | `aws rds reboot-db-instance` | Reboot instance |
    | `aws rds start-db-instance` | Start stopped instance |
    | `aws rds stop-db-instance` | Stop instance |
    
    ### Backups
    
    | Command | Description |
    |---------|-------------|
    | `aws rds create-db-snapshot` | Manual snapshot |
    | `aws rds describe-db-snapshots` | List snapshots |
    | `aws rds restore-db-instance-from-db-snapshot` | Restore from snapshot |
    | `aws rds restore-db-instance-to-point-in-time` | Point-in-time restore |
    | `aws rds copy-db-snapshot` | Copy snapshot |
    
    ### Replicas
    
    | Command | Description |
    |---------|-------------|
    | `aws rds create-db-instance-read-replica` | Create read replica |
    | `aws rds promote-read-replica` | Promote to standalone |
    
    ## Best Practices
    
    ### Security
    
    - **Never make publicly accessible** — use VPC and security groups
    - **Enable encryption** at rest (KMS) and in transit (SSL)
    - **Use IAM authentication** for application access
    - **Store credentials in Secrets Manager** with rotation
    - **Use parameter groups** to enforce SSL
    
    ```bash
    # Enforce SSL in PostgreSQL
    aws rds modify-db-parameter-group \
      --db-parameter-group-name my-pg-params \
      --parameters "ParameterName=rds.force_ssl,ParameterValue=1,ApplyMethod=pending-reboot"
    ```
    
    ### Performance
    
    - **Right-size instances** — monitor CPU, memory, IOPS
    - **Use gp3** for cost-effective performance
    - **Enable Performance Insights** for query analysis
    - **Use read replicas** for read scaling
    - **Optimize queries** — check slow query log
    
    ### High Availability
    
    - **Enable Multi-AZ** for production
    - **Use Aurora** for mission-critical workloads
    - **Configure appropriate backup retention**
    - **Test failover** periodically
    - **Monitor replication lag** for replicas
    
    ### Cost Optimization
    
    - **Use Reserved Instances** for steady-state workloads
    - **Stop dev/test instances** when not in use
    - **Delete old snapshots** regularly
    - **Right-size instance classes**
    
    ## Troubleshooting
    
    ### Cannot Connect
    
    **Causes:**
    1. Security group not allowing access
    2. Instance not in VPC subnet
    3. SSL required but not used
    4. Wrong endpoint/port
    
    **Debug:**
    
    ```bash
    # Check security group
    aws ec2 describe-security-groups --group-ids sg-rds12345
    
    # Check instance status
    aws rds describe-db-instances \
      --db-instance-identifier my-postgres \
      --query "DBInstances[0].{Status:DBInstanceStatus,Endpoint:Endpoint}"
    
    # Test connectivity from EC2
    nc -zv my-postgres.abc123.us-east-1.rds.amazonaws.com 5432
    ```
    
    ### High CPU/Memory
    
    **Debug:**
    
    ```bash
    # Enable Enhanced Monitoring
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --monitoring-interval 60 \
      --monitoring-role-arn arn:aws:iam::123456789012:role/rds-monitoring-role
    
    # Enable Performance Insights
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --enable-performance-insights \
      --performance-insights-retention-period 7
    ```
    
    **Solutions:**
    - Scale up instance class
    - Optimize slow queries
    - Add read replicas
    - Check for locking/blocking
    
    ### Storage Full
    
    **Symptom:** Instance becomes unavailable
    
    **Prevention:**
    
    ```bash
    # Enable storage autoscaling
    aws rds modify-db-instance \
      --db-instance-identifier my-postgres \
      --max-allocated-storage 500
    
    # Set CloudWatch alarm
    aws cloudwatch put-metric-alarm \
      --alarm-name "RDS-Storage-Low" \
      --metric-name FreeStorageSpace \
      --namespace AWS/RDS \
      --dimensions Name=DBInstanceIdentifier,Value=my-postgres \
      --statistic Average \
      --period 300 \
      --threshold 10000000000 \
      --comparison-operator LessThanThreshold \
      --evaluation-periods 2 \
      --alarm-actions arn:aws:sns:us-east-1:123456789012:alerts
    ```
    
    ### Replication Lag
    
    **Monitor:**
    
    ```bash
    aws cloudwatch get-metric-statistics \
      --namespace AWS/RDS \
      --metric-name ReplicaLag \
      --dimensions Name=DBInstanceIdentifier,Value=my-postgres-replica \
      --start-time $(date -d '1 hour ago' -u +%Y-%m-%dT%H:%M:%SZ) \
      --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
      --period 60 \
      --statistics Average
    ```
    
    **Causes:**
    - Replica instance too small
    - Heavy write load
    - Network issues
    - Long-running queries on replica
    
    ## References
    
    - [RDS User Guide](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/)
    - [RDS API Reference](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/)
    - [RDS CLI Reference](https://docs.aws.amazon.com/cli/latest/reference/rds/)
    - [boto3 RDS](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html)
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.

Related