DevOps.Academy
CoursesCurriculumPricing

    Loading…

    ↑ ↓ move · ↵ open · Ctrl K anywhere

    ◔My learningSign in
    DevOps.Academy

    Free, hands-on DevOps lessons. Made with care in India.

    Learn

    All coursesLinux roadmapCurriculumMy learning

    Academy

    PricingCertificates

    Legal

    PrivacyTermsContact

    devops.rajeev.pro

    AWS for DevOpsLesson 10 of 17
    Your progress · 0%
    On this page
    1. RDS: managed relational databases
    2. RDS storage
    3. High availability and read scaling
    4. Backups and snapshots
    5. Parameter groups
    6. Aurora
    7. DynamoDB
    8. DynamoDB capacity
    9. ElastiCache
    10. Availability, replicas and recovery
    11. Maintenance, upgrades and connection management
    12. Aurora and caching
    13. DynamoDB keys, indexes and correctness
    ↖ Course roadmap
    Lesson 10 · Databases

    Managed databases: RDS, DynamoDB, ElastiCache

    Choose relational, key-value or cache storage, then verify backups, capacity and deletion settings.

    30 min read · intermediate · hands-on

    By the end of this lesson you'll be able to

    0 of 5 complete

    RDS: managed relational databases

    RDS runs a relational engine while AWS manages much of the host, patching and infrastructure. You still own the schema, queries, indexes, connection limits, migrations and recovery decisions.

    The lesson used PostgreSQL on a db.t4g.micro, 20 GiB gp3 storage, encryption, one Availability Zone and zero retained automated backups. It was deliberately small and temporary.

    (1) The instance class and engine are visible. (2) The endpoint is private and the instance is single-AZ for this temporary exercise.© Screenshot: DevOps Academy

    (1) The instance class and engine are visible. (2) The endpoint is private and the instance is single-AZ for this temporary exercise.© Screenshot: DevOps Academy

    RDS storage

    gp3 is a general-purpose SSD option. Provisioned IOPS storage is for workloads that need a more controlled I/O profile and can justify the cost. Allocated storage is not the same as free space inside the database; monitor both the RDS volume and the engine.

    High availability and read scaling

    Multi-AZ keeps a standby for failover. It is a high-availability design, not a read-scaling design. Read replicas are separate readable instances that use replication and can serve read traffic. Both features add cost and operational decisions.

    Backups and snapshots

    Automated backups support point-in-time recovery within the retention window. A manual snapshot is a longer-lived recovery artifact. A final snapshot at deletion can be valuable in production but would leave storage behind in this exercise, so the mission explicitly skips it.

    Parameter groups

    Parameter groups hold engine settings. Change them deliberately, check whether a parameter is dynamic or requires a reboot, and test changes against the workload. A parameter group is not a replacement for migrations or query tuning.

    Aurora

    Aurora is an AWS relational engine compatible with MySQL and PostgreSQL APIs. Its distributed storage and cluster model can suit workloads that need those characteristics, but it is not a default upgrade for every RDS database. Start with availability, latency and recovery requirements.

    DynamoDB

    DynamoDB is a managed key-value and document database. Model access patterns first. The partition key distributes data; an optional sort key orders related items within a partition. A table does not provide arbitrary SQL joins, so design queries around the keys and indexes you will actually use.

    The temporary table used on-demand capacity and one string partition key:

    {
        "Name": "temporary-items",
        "Status": "ACTIVE",
        "ItemCount": 0,
        "Key": [{"AttributeName": "pk", "KeyType": "HASH"}]
    }
    

    (1) The table is active. (2) Its partition key is the string attribute pk.© Screenshot: DevOps Academy

    (1) The table is active. (2) Its partition key is the string attribute pk.© Screenshot: DevOps Academy

    DynamoDB capacity

    On-demand capacity is useful for unpredictable traffic or early workloads where capacity planning is not settled. Provisioned capacity is useful when traffic is predictable and you can manage read and write capacity units. Review throttling, adaptive capacity and indexes before changing modes.

    Streams record item changes for consumers. Point-in-time recovery and backups protect table data, but they do not fix a poor key design. DynamoDB Local is useful for development without making network calls to AWS.

    ElastiCache

    ElastiCache provides managed Redis/Valkey or Memcached deployments. A cache should be disposable: define misses, expiry and recovery. Never make the cache the only copy of important data. Redis/Valkey offers richer data structures and persistence choices; Memcached is a simpler distributed cache.

    A managed database is still your responsibility

    AWS manages infrastructure for the service, not your schema, credentials, queries, connection pool or recovery test. Keep credentials out of source control and use least privilege.

    In production

    Use private subnets, security groups that allow only required clients, encryption, monitoring, tested backups and a documented deletion policy. Treat every snapshot and backup as a retained resource with an owner and expiry.

    Availability, replicas and recovery

    Multi-AZ and read replicas solve different problems. Multi-AZ synchronously maintains a standby for instance failover; the standby is not a read endpoint. A read replica is asynchronously replicated and can serve read traffic or be promoted. Use Multi-AZ for availability, replicas for read scale, and both when the workload needs both properties.

    Diagram comparing Multi-AZ standby failover with an asynchronous read replica

    Automated backups support point-in-time restore within the retention window. A manual snapshot is an explicit recovery artifact. In production, set retention and test a restore; in this exercise, deletion uses --skip-final-snapshot because leaving a snapshot behind would leave a billable resource.

    PostgreSQL is one of the available engines. Full configuration exposes availability, backups and security settings. The production template is not a reason to keep production defaults in a temporary exercise.© Screenshot: DevOps Academy

    PostgreSQL is one of the available engines. Full configuration exposes availability, backups and security settings. The production template is not a reason to keep production defaults in a temporary exercise.© Screenshot: DevOps Academy

    Compare Multi-AZ availability before creating. Review backup retention and the maintenance window before accepting defaults.© Screenshot: DevOps Academy

    Compare Multi-AZ availability before creating. Review backup retention and the maintenance window before accepting defaults.© Screenshot: DevOps Academy

    Maintenance, upgrades and connection management

    Maintenance windows make patch and engine-upgrade work predictable. Test a major engine upgrade separately, check extension compatibility, and keep a rollback or restore plan. Parameter groups hold engine settings; a parameter can be dynamic or require a reboot.

    RDS Proxy pools and reuses database connections. It is useful when many short-lived functions would otherwise exhaust the database connection limit. It does not replace query tuning or a sensible pool size.

    IAM database authentication replaces a long-lived password with a short-lived authentication token for supported engines. Secrets Manager is a better fit for a credential that must be rotated and retrieved by an application. Use the smallest role and database grants possible.

    The temporary instance is visible in the database list. The engine and Availability Zone are visible before opening its configuration.© Screenshot: DevOps Academy

    The temporary instance is visible in the database list. The engine and Availability Zone are visible before opening its configuration.© Screenshot: DevOps Academy

    The instance is Available. The class is db.t4g.micro. PostgreSQL and the single Availability Zone are visible.© Screenshot: DevOps Academy

    The instance is Available. The class is db.t4g.micro. PostgreSQL and the single Availability Zone are visible.© Screenshot: DevOps Academy

    Aurora and caching

    Aurora uses a cluster with a writer endpoint and reader endpoint rather than treating every database as one isolated instance. Aurora Serverless v2 scales capacity in fine-grained increments while the cluster remains available to the application. Choose it when the workload needs Aurora's storage and cluster behavior; it is not automatically cheaper.

    ElastiCache Redis or Valkey is for data that can be rebuilt or has an explicit source of truth. Cache-aside is the usual pattern: read the cache, load from the database on a miss, then set an expiry. Define invalidation and stale-data behavior before adding a cache. DAX is a DynamoDB-specific in-memory cache for read-heavy workloads; it changes the client path and should be justified with measured latency and cost.

    DynamoDB keys, indexes and correctness

    The partition key distributes items. A composite primary key adds a sort key, which lets one partition contain an ordered collection of related items. A GSI can use a different partition and sort-key design and is eventually consistent by default. An LSI shares the table partition key and must be declared when the table is created.

    Use Query when the access pattern supplies a partition key; use Scan only for bounded maintenance or discovery work. Conditional writes prevent lost updates. TTL removes expired items asynchronously. Streams publish item changes for downstream consumers, and transactions make a small set of writes commit together.

    The table is Active. Its string partition key is visible. The Indexes column shows the GSI.© Screenshot: DevOps Academy

    The table is Active. Its string partition key is visible. The Indexes column shows the GSI.© Screenshot: DevOps Academy

    On-demand capacity is a good default while traffic is uncertain. Provisioned capacity is useful when request rates are predictable and you can manage capacity units. Both modes still need throttling metrics and a key design that avoids hot partitions.

    ⌘
    Mini mission

    One relational database and one key-value table

    Create a small encrypted private PostgreSQL RDS instance and an on-demand DynamoDB table, inspect their settings, then delete both without retaining a final RDS snapshot.

    Input: AWS CLI credentials allowed to create and delete temporary RDS and DynamoDB resourcesOutput: Verified RDS and DynamoDB settings followed by a clean account
    Reveal one safe solution
    $ export AWS_REGION=ap-south-1
    $ export DB_ID="academy-postgres-$RANDOM"
    $ export TABLE="academy-items-$RANDOM"
    $ export DB_PASSWORD="Use-a-temporary-secret-here"
    $ aws rds create-db-instance --region "$AWS_REGION" --db-instance-identifier "$DB_ID" \
        --db-instance-class db.t4g.micro --engine postgres --allocated-storage 20 \
        --storage-type gp3 --master-username academy --master-user-password "$DB_PASSWORD" \
        --db-subnet-group-name default --backup-retention-period 0 --no-multi-az \
        --no-publicly-accessible --storage-encrypted --no-deletion-protection
    $ aws dynamodb create-table --region "$AWS_REGION" --table-name "$TABLE" \
        --attribute-definitions AttributeName=pk,AttributeType=S AttributeName=gsi,AttributeType=S \
        --key-schema AttributeName=pk,KeyType=HASH \
        --global-secondary-indexes 'IndexName=GSI1,KeySchema=[{AttributeName=gsi,KeyType=HASH}],Projection={ProjectionType=ALL}' \
        --billing-mode PAY_PER_REQUEST
    $ aws dynamodb wait table-exists --region "$AWS_REGION" --table-name "$TABLE"
    $ aws dynamodb put-item --region "$AWS_REGION" --table-name "$TABLE" --item '{"pk":{"S":"lesson-10"},"gsi":{"S":"database"},"value":{"N":"10"}}'
    $ aws dynamodb query --region "$AWS_REGION" --table-name "$TABLE" --index-name GSI1 \
        --key-condition-expression 'gsi = :g' --expression-attribute-values '{":g":{"S":"database"}}' \
        --query 'Items' --output json
    [
        {"pk":{"S":"lesson-10"},"gsi":{"S":"database"},"value":{"N":"10"}}
    ]
    $ aws dynamodb scan --region "$AWS_REGION" --table-name "$TABLE" --query 'Items' --output json
    [
        {"pk":{"S":"lesson-10"},"gsi":{"S":"database"},"value":{"N":"10"}}
    ]
    $ aws dynamodb describe-table --region "$AWS_REGION" --table-name "$TABLE" \
        --query 'Table.{Name:TableName,Status:TableStatus,Keys:KeySchema}' --output table
    ---------------------------------------------
    |              DescribeTable                 |
    +---------+--------+-------------------------+
    | Name    | Status | Keys                    |
    +---------+--------+-------------------------+
    | TABLE   | ACTIVE | pk / HASH               |
    +---------+--------+-------------------------+
    $ aws rds describe-db-instances --region "$AWS_REGION" --db-instance-identifier "$DB_ID" \
        --query 'DBInstances[0].{Status:DBInstanceStatus,Class:DBInstanceClass,Storage:AllocatedStorage,MultiAZ:MultiAZ,Backups:BackupRetentionPeriod,Encrypted:StorageEncrypted,Public:PubliclyAccessible}' --output table
    $ aws rds delete-db-instance --region "$AWS_REGION" --db-instance-identifier "$DB_ID" \
        --skip-final-snapshot --delete-automated-backups
    $ aws dynamodb delete-table --region "$AWS_REGION" --table-name "$TABLE"
    $ aws dynamodb describe-table --region "$AWS_REGION" --table-name "$TABLE"
    An error occurred (ResourceNotFoundException) when calling the DescribeTable operation
    $ aws rds wait db-instance-deleted --region "$AWS_REGION" --db-instance-identifier "$DB_ID"
    $ aws rds describe-db-instances --region "$AWS_REGION" --db-instance-identifier "$DB_ID"
    An error occurred (DBInstanceNotFound) when calling the DescribeDBInstances operation
    
    aws rds create-db-instance --region "$AWS_REGION" --db-instance-identifier "$DB_ID" \
    • awsthe AWS command line
    • --regionwhich Region
    aws dynamodb scan --region "$AWS_REGION" --table-name "$TABLE" --query 'Items' --output json
    • --querypick fields from the JSON response
    • --outputoutput format

    Use a secret manager or an interactive secret prompt for a real password. The placeholder above is only a shape; never paste a production password into shell history.

    Try it yourself

    0 of 5 steps done

    Run each task in your own account or terminal, then tick it off.

    Knowledge check

    Quick check

    Question 1 of 7

    When is RDS a good fit?

    Go deeper

    Official reading for this lesson

    • DocsAmazon RDS User GuideAWS Docs ↗
    • GuideRDS Multi-AZ deploymentsAWS Docs ↗
    • DocsAmazon DynamoDB Developer GuideAWS Docs ↗
    • DocsDynamoDB capacity modesAWS Docs ↗
    • DocsAmazon ElastiCache documentationAWS Docs ↗

    Or get every quiz answer right and it completes itself.

    ← PreviousCloudFront: a fast edge in front of your appNext lesson →Containers on AWS: ECR, ECS and EKS