MENU
RDS
Amazon RDS is a managed relational database service that supports several database engines, including MySQL, PostgreSQL, Oracle, SQL Server, MariaDB, and Amazon Aurora. It suits applications that require ACID compliance and data consistency.The RDS maintenance window is the opportunity to control when DB instance modifications, database engine version upgrades, and software patching occur, when they are requested or required. If a preferred weekly maintenance window is not specified when creating a DB instance, a 30-minute default value is assigned. Running a DB instance as a Multi-AZ deployment can further reduce the impact of a maintenance event.
For high-performance OLTP workloads, choose RDS Provisioned IOPS (SSD) Storage; for workloads with moderate I/O requirements, choose RDS General Purpose (SSD) Storage. RDS magnetic storage suits small workloads where data is accessed less frequently and is not recommended for production database instances.
Fully Managed Service
Amazon RDS is a fully managed service: AWS manages the underlying infrastructure, software updates, backups, and monitoring, letting customers focus on their applications.Multiple Database Engines
Amazon RDS supports multiple database engines — Amazon Aurora, MySQL, PostgreSQL, Oracle, and SQL Server — so customers can choose the engine that best fits their needs. For RDS for MySQL, MySQL 8.4 LTS is available as a selectable engine version for new and upgraded DB instances, alongside other actively supported MySQL versions.Scalability
Amazon RDS is designed to scale automatically based on demand, so capacity can be added or removed without downtime. It can handle millions of requests per second and scale to support very large workloads.Multi-AZ Deployments
Multi-AZ deployments automatically replicate data across multiple Availability Zones to provide high availability and disaster recovery.When a DB instance runs as a Multi-AZ deployment, the "primary" serves database writes and reads. RDS also provisions and maintains a "standby" behind the scenes, an up-to-date replica of the primary. The standby is "promoted" in failover scenarios and is automatically provisioned in a different Availability Zone of the same Region as the primary.
Read Replicas
Read Replicas are read-only copies of a database that offload read traffic and improve performance.RDS for MySQL, MariaDB, and PostgreSQL allow up to 15 read replicas per source DB instance. RDS for Oracle and SQL Server allow up to 5 read replicas per source DB instance. RDS (except RDS for SQL Server) supports cross-region read replicas; the replication lag depends on network latency between the two regions. Read replicas in RDS for MySQL, MariaDB, PostgreSQL, Oracle, and SQL Server are implemented using each engine's native asynchronous replication (compare with MySQL's own Replication mechanism). Amazon Aurora uses a different, but still asynchronous, replication mechanism.
For Aurora, RDS for MySQL, and MariaDB, three tiers of read replicas can be created: a second-tier read replica from an existing first-tier replica, and a third-tier replica from second-tier replicas. Creating second- and third-tier read replicas can move replication load from the primary database instance to different replica tiers. A read replica can be promoted into a standalone DB instance.
Security
Amazon RDS provides encryption at rest and in transit, fine-grained access control using IAM roles and policies, and support for AWS Key Management Service (KMS) for managing encryption keys. See also Users and Privileges for database-level access control.Optimized Writes and Reads
MySQL protects against data loss by writing 16KiB data pages in memory twice to durable storage — first to the "doublewrite buffer", then to table storage. RDS Optimized Writes writes 16KiB data pages directly to data files reliably and durably in one step, using the Torn Write Prevention feature of the AWS Nitro System, at no additional cost. RDS for MySQL users should implement Optimized Writes for up to 2x improved write transaction throughput; write-heavy workloads such as digital payments, financial trading, and online gaming benefit most. Aurora MySQL-Compatible Edition already avoids the doublewrite buffer: it replicates data six ways across three Availability Zones and uses a quorum-based approach to durably write and correctly read data.Workloads that use temporary objects in MySQL and MariaDB for query processing benefit from RDS Optimized Reads, which place temporary objects on the DB instance's NVMe-based instance storage instead of the Amazon EBS volume, speeding up complex query processing by up to 2x.
Integration with Other AWS Services
Amazon RDS integrates with services such as AWS Lambda, AWS IAM, and Amazon CloudWatch, supporting scalable and highly available applications.Ease of Use
Amazon RDS provides a simple web interface and APIs for managing databases, so databases can be created, modified, and deleted with just a few clicks.For production databases, enable Enhanced Monitoring, which provides access to over 50 CPU, memory, file system, and disk I/O metrics for deeper visibility into instance health. Enable Enhanced Monitoring on the DB instance and set a granularity; metrics are delivered to CloudWatch Logs, from which metric filters and dashboard graphs can be created. For deeper diagnostics, visualization of database load, and longer data retention, use Performance Insights.
RDS Proxy
Amazon RDS Proxy is a fully managed database proxy that sits between an application and its RDS database instances. It pools and shares database connections, improving the scalability and availability of a database workload, and can handle hundreds of thousands of connections per second — useful for high-traffic applications or many client connections. RDS Proxy also offers connection multiplexing, read/write splitting, and connection pooling. While RDS read replicas are used for read scaling and backup purposes, RDS Proxy is used for connection pooling and management.DevOps Guru & RDS Performance
Amazon DevOps Guru for RDS is an ML-powered capability for Amazon RDS (including Aurora) that automatically detects and diagnoses database performance and operational issues, aiming to resolve issues in minutes rather than days. Amazon RDS Performance Insights is a database performance tuning and monitoring feature that collects and visualizes RDS performance metrics, helping assess database load and determine when and where to take action. DevOps Guru for RDS monitors those metrics, detects performance issues, analyzes them, and reports what is wrong and what can be done about it.RDS Blue/Green Deployments
In an RDS Blue/Green Deployment, the blue environment is the current production environment. The green environment is a staging environment that becomes the new production environment after switchover.Backups and Snapshots
The automated backup feature enables point-in-time recovery of a DB instance. When automated backups are turned on, RDS performs a full daily snapshot (during the preferred backup window) and captures transaction logs as updates are made. On a point-in-time recovery, transaction logs are applied to the most appropriate daily backup to restore the DB instance to the requested time.RDS retains backups for a user-specified retention period, 7 days by default and up to 35 days. A point-in-time restore can target any second within the retention period, up to the Latest Restorable Time, obtainable via the DescribeDBInstances API (typically within the last five minutes) or the "Description" tab in the console.
DB Snapshots are user-initiated: they back up a DB instance in a known state as frequently as desired and can be restored to that state at any time. DB Snapshots are created via the console, the CreateDBSnapshot API, or the create-db-snapshot command, and are kept until explicitly deleted.
Snapshots taken for automated backups can be copied (via the console or the copy-db-snapshot command) or used for snapshot restore. A restore operation, whether to a point in time or from a DB Snapshot, creates a new DB instance with a new endpoint (the old instance can be deleted afterward), so multiple DB instances can be created from one snapshot or point in time. RDS DB snapshots and automated backups are stored in Amazon S3 (see also Backup and Recovery for MySQL's own backup mechanisms).
Manage the automated backup retention period via the console, the ModifyDBInstance API, or the modify-db-instance command (the RetentionPeriod parameter); setting it to 0 turns off automated backups (not recommended). Manage user-created DB Snapshots via the "Snapshots" section of the RDS Console, the DescribeDBSnapshots API or describe-db-snapshots command, and delete them with the DeleteDBSnapshot API or delete-db-snapshot command.
It is normal to see 1 or 2 more automated snapshots than the number of days in the retention period: one extra snapshot ensures point-in-time restore is possible throughout the retention period, and a new automated snapshot is always created before the oldest one is deleted.
When a DB instance is deleted, a final DB snapshot can be created on deletion and later used to restore that instance; RDS retains this final snapshot along with all other manually created snapshots after deletion. Automated backups are deleted when the DB instance is deleted; only manually created DB snapshots are retained.
Migration of DB instances from inside to outside a VPC is not supported: for security reasons, a DB Snapshot of a DB instance inside a VPC cannot be restored outside the VPC, and the same applies to "Restore to Point in Time".
Example: Accessing RDS from AWS Lambda
The following example uses a Python AWS Lambda function to read a message from an event, insert it into an Amazon RDS MySQL table inside a VPC, and log the resulting rows. The database connection is created outside the handler so it can be reused by later invocations of the same execution environment.By default, an account is allowed up to a total of 40 Amazon RDS DB instances. No limit is imposed on the number of databases per instance except for RDS for Oracle (1 database per instance) and RDS for SQL Server (100 databases per instance). A DB Parameter Group acts as a container for engine configuration values applied to one or more DB instances. RDS can also run on premises using Amazon RDS on Outposts.
import sys
import logging
import pymysql
import json
# RDS settings
rds_host = "mysqlforlambda.cdipnbm2csku.us-west-2.rds.amazonaws.com"
user_name = "admin"
password = "password"
db_name = "ExampleDB"
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Create the database connection outside of the handler to allow connections
# to be re-used by subsequent function invocations.
try:
conn = pymysql.connect(host=rds_host, user=user_name, passwd=password,
db=db_name, connect_timeout=5)
except pymysql.MySQLError as e:
logger.error("ERROR: Unexpected error: Could not connect to MySQL instance.")
logger.error(e)
sys.exit()
logger.info("SUCCESS: Connection to RDS MySQL instance succeeded")
def lambda_handler(event, context):
"""
This function creates a new RDS database table and writes records to it.
"""
message = event['Records'][0]['body']
data = json.loads(message)
CustID = data['CustID']
Name = data['Name']
item_count = 0
sql_string = f"insert into Customer (CustID, Name) values({CustID}, '{Name}')"
with conn.cursor() as cur:
cur.execute("create table if not exists Customer "
"( CustID int NOT NULL, Name varchar(255) NOT NULL, PRIMARY KEY (CustID))")
cur.execute(sql_string)
conn.commit()
cur.execute("select * from Customer")
logger.info("The following items have been added to the database:")
for row in cur:
item_count += 1
logger.info(row)
conn.commit()
return "Added %d items to RDS MySQL table" % (item_count)# Create a manual DB snapshot
aws rds create-db-snapshot \
--db-instance-identifier mydatabase \
--db-snapshot-identifier mydatabase-manual-snapshot
# Find the latest restorable time for point-in-time recovery
aws rds describe-db-instances \
--db-instance-identifier mydatabase \
--query "DBInstances[0].LatestRestorableTime"
# Restore a new DB instance from a snapshot (creates a new endpoint)
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier mydatabase-restored \
--db-snapshot-identifier mydatabase-manual-snapshot
# List and then delete a manually created snapshot
aws rds describe-db-snapshots --db-instance-identifier mydatabase
aws rds delete-db-snapshot --db-snapshot-identifier mydatabase-manual-snapshot