Files
skills/public/cloud-aws-databases.html
zeekayandHanzo Dev 9e10c1c10e Each llms index points at the other two
hanzoskills.com/llms.txt now opens with the install line, the API
reference index and the company index, so an agent that lands on any
one of the three can find the rest.

robots.txt claimed 537 documents while llms.txt counts 920. The number
is gone from robots.txt; llms.txt derives it.

public/ is regenerated from scripts/site.py, which it had fallen
behind: the copy-prompt menu and agent bar were in the generator and
not in the committed pages. tests/site.mjs passes against the result.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-11 00:27:59 -07:00

796 lines
36 KiB
HTML

<!doctype html>
<html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>cloud-aws-databases</title>
<meta name="color-scheme" content="dark">
<style>
/* Committed to one visual world: a dark instrument panel. No light variant —
the dot field and the hairline rules only read on black, and a naive
inversion would wash both out. Every colour is painted explicitly so the page
never borrows a host background. */
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
:root{
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
--font-zen-pixel-square:'Zen Pixel Square',monospace;
--mono:var(--font-zen-mono);
--sans:var(--font-zen-sans);
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
--r:999px; --r-soft:14px;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
/* The dot field. A halftone made of one repeating radial-gradient, faded out
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
/* No overflow clip here: the dot field is inset to the box already, and a clip
would cut off the copy-prompt menu. */
.hero{position:relative;border-bottom:1px solid var(--line)}
.hero::before{content:"";position:absolute;inset:0;
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
background-size:7px 7px;
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
pointer-events:none}
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
nav{border-bottom:1px solid var(--line)}
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
justify-content:space-between;align-items:center;gap:1rem}
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
text-transform:uppercase;color:var(--ink);text-decoration:none;
display:inline-flex;align-items:center;gap:.6rem}
.brand i{font-style:normal;color:var(--faint)}
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
text-transform:uppercase;color:var(--soft);text-decoration:none}
nav a.up:hover{color:var(--ink)}
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
h1 em{font-style:normal;color:var(--faint)}
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
line-height:1.2;font-weight:400}
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
.btn.solid:hover{background:#d8d8d4}
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
/* Copy-prompt selector. Each row copies the prompt for its own target. */
.copy{position:relative;display:inline-flex}
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
padding:.4rem;display:flex;flex-direction:column;
box-shadow:0 12px 32px rgba(0,0,0,.75)}
.menu[hidden]{display:none}
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
white-space:nowrap}
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
.mi:hover .mark{color:var(--ink)}
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
letter-spacing:.1em;text-transform:uppercase}
/* Works-with bar: one scrolling row, name and mark per agent. */
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
display:flex;align-items:center}
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
-webkit-overflow-scrolling:touch;
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
.bar::-webkit-scrollbar{display:none}
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
text-decoration:none;background:var(--ground)}
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
.agent .mark{width:.95rem;height:.95rem}
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
p{margin:0 0 1rem;max-width:70ch}
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
li{margin:.22rem 0}
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
text-decoration-color:var(--line-hi)}
a:hover{text-decoration-color:var(--ink)}
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
display:block;overflow-x:auto}
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
.curl{display:block;background:var(--panel);border:1px solid var(--line);
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
white-space:pre;line-height:1.9}
.curl b{color:var(--ink);font-weight:400}
.curl i{font-style:normal;color:var(--faint)}
/* index */
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
#q:focus{outline:none;border-color:var(--soft)}
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
text-transform:uppercase;margin:0 0 2rem}
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
padding-bottom:.45rem}
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
border-radius:var(--r-soft);text-decoration:none}
.row:hover{background:#0a0a0a}
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
color:var(--faint);font-size:.85rem}
footer a{color:var(--soft)}
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
margin:0 0 2rem;font-size:.85rem}
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
border-bottom:1px solid var(--line);padding-bottom:.4rem}
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
.fmap a:hover{text-decoration:underline}
.fmap div{color:var(--faint);line-height:1.5}
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
@media (max-width:640px){
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
.btns{gap:.5rem}
.btn{padding:.75rem 1.15rem;font-size:.68rem}
.copy,.copy .btn{width:100%;justify-content:center}
.menu{left:0;right:0;min-width:0}
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
.strip b{border-right:0;padding-right:0}
.bar{width:100%}
}
</style>
<link rel="alternate" type="text/markdown" href="/cloud-aws-databases.md">
<link rel="icon" href="/favicon.svg">
<link rel="canonical" href="https://hanzoskills.com/cloud-aws-databases">
</head>
<!-- Reading this with a machine? Every page here is also plain markdown.
This one: https://hanzoskills.com/cloud-aws-databases.md
Index: https://hanzoskills.com/llms.txt
Corpus: https://hanzoskills.com/all.md
Append .md to any path for the markdown twin. -->
<body>
<nav><div class="in">
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
<a class="up" href="/">All skills</a>
</div></nav>
<div class="wrap">
<h1>cloud-aws-databases</h1><p class="lede">AWS database services - RDS, DynamoDB, ElastiCache, Aurora, migration, backup, and optimization</p><h1>AWS Databases</h1>
<p><strong>Scope</strong>: AWS databases - RDS, DynamoDB, ElastiCache, Aurora Serverless, migration strategies, backup and recovery <strong>Lines</strong>: ~350 <strong>Last Updated</strong>: 2025-10-25 <strong>Format Version</strong>: 1.0 (Atomic)</p>
<hr>
<h2>When to Use This Skill</h2>
<p>Activate this skill when:</p>
<ul><li>Deploying managed relational databases with RDS</li><li>Building NoSQL applications with DynamoDB</li><li>Implementing caching with ElastiCache (Redis/Memcached)</li><li>Setting up Aurora Serverless for variable workloads</li><li>Migrating databases to AWS</li><li>Configuring database backups and point-in-time recovery</li><li>Optimizing database performance and read replicas</li><li>Troubleshooting database connectivity or performance issues</li></ul>
<h2>Core Concepts</h2>
<h3>Concept 1: RDS (Relational Database Service)</h3>
<p><strong>RDS engines</strong>:</p>
<ul><li><strong>PostgreSQL</strong>: Full-featured, JSON support, extensions</li><li><strong>MySQL</strong>: Popular, good ecosystem</li><li><strong>Aurora</strong>: AWS-optimized, 5x MySQL / 3x PostgreSQL performance</li><li><strong>MariaDB</strong>: MySQL fork, additional features</li><li><strong>Oracle</strong>: Commercial, enterprise features</li><li><strong>SQL Server</strong>: Microsoft, Windows integration</li></ul>
<pre><code class="lang-python">import boto3
rds = boto3.client(&#x27;rds&#x27;)
def create_rds_instance():
&quot;&quot;&quot;Create RDS PostgreSQL instance with Multi-AZ&quot;&quot;&quot;
response = rds.create_db_instance(
DBInstanceIdentifier=&#x27;myapp-db&#x27;,
DBInstanceClass=&#x27;db.t3.medium&#x27;, # 2 vCPU, 4 GB RAM
Engine=&#x27;postgres&#x27;,
EngineVersion=&#x27;15.4&#x27;,
MasterUsername=&#x27;dbadmin&#x27;,
MasterUserPassword=&#x27;SecurePassword123!&#x27;, # Example only - use AWS Secrets Manager in production
AllocatedStorage=100, # GB
StorageType=&#x27;gp3&#x27;, # General purpose SSD
StorageEncrypted=True,
MultiAZ=True, # High availability
DBSubnetGroupName=&#x27;my-db-subnet-group&#x27;,
VpcSecurityGroupIds=[&#x27;sg-0123456789abcdef0&#x27;],
BackupRetentionPeriod=7, # Days
PreferredBackupWindow=&#x27;03:00-04:00&#x27;, # UTC
PreferredMaintenanceWindow=&#x27;sun:04:00-sun:05:00&#x27;,
EnableCloudwatchLogsExports=[&#x27;postgresql&#x27;],
Tags=[
{&#x27;Key&#x27;: &#x27;Name&#x27;, &#x27;Value&#x27;: &#x27;myapp-db&#x27;},
{&#x27;Key&#x27;: &#x27;Environment&#x27;, &#x27;Value&#x27;: &#x27;production&#x27;}
]
)
print(f&quot;Creating RDS instance: {response[&#x27;DBInstance&#x27;][&#x27;DBInstanceIdentifier&#x27;]}&quot;)
return response[&#x27;DBInstance&#x27;][&#x27;Endpoint&#x27;][&#x27;Address&#x27;]
def create_read_replica(source_db_id):
&quot;&quot;&quot;Create read replica for scaling reads&quot;&quot;&quot;
response = rds.create_db_instance_read_replica(
DBInstanceIdentifier=f&#x27;{source_db_id}-replica-1&#x27;,
SourceDBInstanceIdentifier=source_db_id,
DBInstanceClass=&#x27;db.t3.medium&#x27;,
PubliclyAccessible=False,
Tags=[
{&#x27;Key&#x27;: &#x27;Name&#x27;, &#x27;Value&#x27;: f&#x27;{source_db_id}-replica&#x27;},
{&#x27;Key&#x27;: &#x27;Role&#x27;, &#x27;Value&#x27;: &#x27;read-replica&#x27;}
]
)
print(f&quot;Creating read replica: {response[&#x27;DBInstance&#x27;][&#x27;DBInstanceIdentifier&#x27;]}&quot;)</code></pre>
<h3>Concept 2: DynamoDB</h3>
<p><strong>DynamoDB concepts</strong>:</p>
<ul><li><strong>Tables</strong>: Primary key (partition + sort key)</li><li><strong>Indexes</strong>: GSI (global), LSI (local)</li><li><strong>Capacity modes</strong>: On-demand vs provisioned</li><li><strong>Streams</strong>: Change data capture</li></ul>
<pre><code class="lang-python">import boto3
from boto3.dynamodb.conditions import Key, Attr
from datetime import datetime
dynamodb = boto3.resource(&#x27;dynamodb&#x27;)
def create_dynamodb_table():
&quot;&quot;&quot;Create DynamoDB table with indexes&quot;&quot;&quot;
table = dynamodb.create_table(
TableName=&#x27;Users&#x27;,
KeySchema=[
{&#x27;AttributeName&#x27;: &#x27;userId&#x27;, &#x27;KeyType&#x27;: &#x27;HASH&#x27;}, # Partition key
],
AttributeDefinitions=[
{&#x27;AttributeName&#x27;: &#x27;userId&#x27;, &#x27;AttributeType&#x27;: &#x27;S&#x27;},
{&#x27;AttributeName&#x27;: &#x27;email&#x27;, &#x27;AttributeType&#x27;: &#x27;S&#x27;},
{&#x27;AttributeName&#x27;: &#x27;createdAt&#x27;, &#x27;AttributeType&#x27;: &#x27;S&#x27;}
],
GlobalSecondaryIndexes=[
{
&#x27;IndexName&#x27;: &#x27;email-index&#x27;,
&#x27;KeySchema&#x27;: [
{&#x27;AttributeName&#x27;: &#x27;email&#x27;, &#x27;KeyType&#x27;: &#x27;HASH&#x27;}
],
&#x27;Projection&#x27;: {&#x27;ProjectionType&#x27;: &#x27;ALL&#x27;},
&#x27;ProvisionedThroughput&#x27;: {
&#x27;ReadCapacityUnits&#x27;: 5,
&#x27;WriteCapacityUnits&#x27;: 5
}
},
{
&#x27;IndexName&#x27;: &#x27;created-index&#x27;,
&#x27;KeySchema&#x27;: [
{&#x27;AttributeName&#x27;: &#x27;createdAt&#x27;, &#x27;KeyType&#x27;: &#x27;HASH&#x27;}
],
&#x27;Projection&#x27;: {&#x27;ProjectionType&#x27;: &#x27;KEYS_ONLY&#x27;},
&#x27;ProvisionedThroughput&#x27;: {
&#x27;ReadCapacityUnits&#x27;: 5,
&#x27;WriteCapacityUnits&#x27;: 5
}
}
],
BillingMode=&#x27;PROVISIONED&#x27;,
ProvisionedThroughput={
&#x27;ReadCapacityUnits&#x27;: 10,
&#x27;WriteCapacityUnits&#x27;: 10
},
StreamSpecification={
&#x27;StreamEnabled&#x27;: True,
&#x27;StreamViewType&#x27;: &#x27;NEW_AND_OLD_IMAGES&#x27;
},
Tags=[
{&#x27;Key&#x27;: &#x27;Environment&#x27;, &#x27;Value&#x27;: &#x27;production&#x27;}
]
)
# Wait for table to be created
table.wait_until_exists()
print(f&quot;Created table: {table.table_name}&quot;)
return table
# CRUD operations
table = dynamodb.Table(&#x27;Users&#x27;)
def create_user(user_id, email, name):
&quot;&quot;&quot;Create user item&quot;&quot;&quot;
table.put_item(
Item={
&#x27;userId&#x27;: user_id,
&#x27;email&#x27;: email,
&#x27;name&#x27;: name,
&#x27;createdAt&#x27;: datetime.utcnow().isoformat(),
&#x27;status&#x27;: &#x27;active&#x27;
}
)
def get_user(user_id):
&quot;&quot;&quot;Get user by ID&quot;&quot;&quot;
response = table.get_item(Key={&#x27;userId&#x27;: user_id})
return response.get(&#x27;Item&#x27;)
def query_by_email(email):
&quot;&quot;&quot;Query using GSI&quot;&quot;&quot;
response = table.query(
IndexName=&#x27;email-index&#x27;,
KeyConditionExpression=Key(&#x27;email&#x27;).eq(email)
)
return response[&#x27;Items&#x27;]
def update_user(user_id, name):
&quot;&quot;&quot;Update user with atomic increment&quot;&quot;&quot;
response = table.update_item(
Key={&#x27;userId&#x27;: user_id},
UpdateExpression=&#x27;SET #name = :name, updatedAt = :timestamp ADD loginCount :inc&#x27;,
ExpressionAttributeNames={&#x27;#name&#x27;: &#x27;name&#x27;},
ExpressionAttributeValues={
&#x27;:name&#x27;: name,
&#x27;:timestamp&#x27;: datetime.utcnow().isoformat(),
&#x27;:inc&#x27;: 1
},
ReturnValues=&#x27;ALL_NEW&#x27;
)
return response[&#x27;Attributes&#x27;]</code></pre>
<h3>Concept 3: ElastiCache</h3>
<p><strong>Redis vs Memcached</strong>:</p>
<ul><li><strong>Redis</strong>: Data structures, persistence, replication, pub/sub</li><li><strong>Memcached</strong>: Simple key-value, multi-threaded, faster for simple caching</li></ul>
<pre><code class="lang-python">import boto3
import redis
elasticache = boto3.client(&#x27;elasticache&#x27;)
def create_redis_cluster():
&quot;&quot;&quot;Create ElastiCache Redis cluster&quot;&quot;&quot;
response = elasticache.create_replication_group(
ReplicationGroupId=&#x27;myapp-redis&#x27;,
ReplicationGroupDescription=&#x27;Redis cluster for myapp&#x27;,
Engine=&#x27;redis&#x27;,
EngineVersion=&#x27;7.0&#x27;,
CacheNodeType=&#x27;cache.t3.medium&#x27;,
NumCacheClusters=2, # Primary + 1 replica
AutomaticFailoverEnabled=True,
MultiAZEnabled=True,
CacheSubnetGroupName=&#x27;my-cache-subnet-group&#x27;,
SecurityGroupIds=[&#x27;sg-0123456789abcdef0&#x27;],
AtRestEncryptionEnabled=True,
TransitEncryptionEnabled=True,
SnapshotRetentionLimit=5,
SnapshotWindow=&#x27;03:00-05:00&#x27;,
Tags=[
{&#x27;Key&#x27;: &#x27;Name&#x27;, &#x27;Value&#x27;: &#x27;myapp-redis&#x27;},
{&#x27;Key&#x27;: &#x27;Environment&#x27;, &#x27;Value&#x27;: &#x27;production&#x27;}
]
)
print(f&quot;Creating Redis cluster: {response[&#x27;ReplicationGroup&#x27;][&#x27;ReplicationGroupId&#x27;]}&quot;)
# Use Redis client
def connect_to_redis(endpoint, port=6379):
&quot;&quot;&quot;Connect to ElastiCache Redis&quot;&quot;&quot;
# For encrypted connections
client = redis.Redis(
host=endpoint,
port=port,
decode_responses=True,
ssl=True,
ssl_cert_reqs=None # For self-signed certs
)
return client
# Caching pattern
def get_user_cached(user_id, redis_client):
&quot;&quot;&quot;Get user with Redis caching&quot;&quot;&quot;
cache_key = f&#x27;user:{user_id}&#x27;
# Check cache
cached = redis_client.get(cache_key)
if cached:
return json.loads(cached)
# Cache miss - fetch from DB
user = get_user_from_db(user_id)
# Store in cache (1 hour TTL)
redis_client.setex(
cache_key,
3600,
json.dumps(user)
)
return user</code></pre>
<h3>Concept 4: Aurora Serverless</h3>
<p><strong>Aurora Serverless use cases</strong>:</p>
<ul><li>Variable workloads (dev/test environments)</li><li>Unpredictable traffic patterns</li><li>Multi-tenant applications</li><li>Infrequent usage (pauses when idle)</li></ul>
<pre><code class="lang-python">def create_aurora_serverless_cluster():
&quot;&quot;&quot;Create Aurora Serverless v2 cluster&quot;&quot;&quot;
response = rds.create_db_cluster(
DBClusterIdentifier=&#x27;myapp-aurora&#x27;,
Engine=&#x27;aurora-postgresql&#x27;,
EngineVersion=&#x27;15.4&#x27;,
MasterUsername=&#x27;dbadmin&#x27;,
MasterUserPassword=&#x27;SecurePassword123!&#x27;, # Example only - use AWS Secrets Manager in production
DatabaseName=&#x27;myapp&#x27;,
DBSubnetGroupName=&#x27;my-db-subnet-group&#x27;,
VpcSecurityGroupIds=[&#x27;sg-0123456789abcdef0&#x27;],
ServerlessV2ScalingConfiguration={
&#x27;MinCapacity&#x27;: 0.5, # ACUs (Aurora Capacity Units)
&#x27;MaxCapacity&#x27;: 2.0
},
EnableHttpEndpoint=True, # Data API
StorageEncrypted=True,
BackupRetentionPeriod=7,
Tags=[
{&#x27;Key&#x27;: &#x27;Name&#x27;, &#x27;Value&#x27;: &#x27;myapp-aurora&#x27;},
{&#x27;Key&#x27;: &#x27;Type&#x27;, &#x27;Value&#x27;: &#x27;serverless&#x27;}
]
)
cluster_id = response[&#x27;DBCluster&#x27;][&#x27;DBClusterIdentifier&#x27;]
# Create serverless instance
rds.create_db_instance(
DBInstanceIdentifier=f&#x27;{cluster_id}-instance-1&#x27;,
DBInstanceClass=&#x27;db.serverless&#x27;,
Engine=&#x27;aurora-postgresql&#x27;,
DBClusterIdentifier=cluster_id
)
print(f&quot;Created Aurora Serverless cluster: {cluster_id}&quot;)</code></pre>
<hr>
<h2>Patterns</h2>
<h3>Pattern 1: Database Migration with DMS</h3>
<p><strong>When to use</strong>: Migrate databases to AWS with minimal downtime</p>
<pre><code class="lang-python">import boto3
dms = boto3.client(&#x27;dms&#x27;)
def create_dms_replication():
&quot;&quot;&quot;Create DMS replication instance and task&quot;&quot;&quot;
# Create replication instance
replication_response = dms.create_replication_instance(
ReplicationInstanceIdentifier=&#x27;myapp-migration&#x27;,
ReplicationInstanceClass=&#x27;dms.t3.medium&#x27;,
AllocatedStorage=100,
VpcSecurityGroupIds=[&#x27;sg-0123456789abcdef0&#x27;],
MultiAZ=False,
EngineVersion=&#x27;3.4.7&#x27;,
PubliclyAccessible=False
)
# Wait for instance to be available
waiter = dms.get_waiter(&#x27;replication_instance_available&#x27;)
waiter.wait(
Filters=[
{&#x27;Name&#x27;: &#x27;replication-instance-id&#x27;, &#x27;Values&#x27;: [&#x27;myapp-migration&#x27;]}
]
)
# Create source endpoint (on-premises database)
source_endpoint = dms.create_endpoint(
EndpointIdentifier=&#x27;source-postgres&#x27;,
EndpointType=&#x27;source&#x27;,
EngineName=&#x27;postgres&#x27;,
ServerName=&#x27;onprem-db.example.com&#x27;,
Port=5432,
DatabaseName=&#x27;myapp&#x27;,
Username=&#x27;migration_user&#x27;,
Password=&#x27;migration_password&#x27; # Example only - use AWS Secrets Manager in production
)
# Create target endpoint (RDS)
target_endpoint = dms.create_endpoint(
EndpointIdentifier=&#x27;target-rds&#x27;,
EndpointType=&#x27;target&#x27;,
EngineName=&#x27;postgres&#x27;,
ServerName=&#x27;myapp-db.abc123.us-east-1.rds.amazonaws.com&#x27;,
Port=5432,
DatabaseName=&#x27;myapp&#x27;,
Username=&#x27;dbadmin&#x27;,
Password=&#x27;SecurePassword123!&#x27; # Example only - use AWS Secrets Manager in production
)
# Create migration task
dms.create_replication_task(
ReplicationTaskIdentifier=&#x27;myapp-full-load&#x27;,
SourceEndpointArn=source_endpoint[&#x27;Endpoint&#x27;][&#x27;EndpointArn&#x27;],
TargetEndpointArn=target_endpoint[&#x27;Endpoint&#x27;][&#x27;EndpointArn&#x27;],
ReplicationInstanceArn=replication_response[&#x27;ReplicationInstance&#x27;][&#x27;ReplicationInstanceArn&#x27;],
MigrationType=&#x27;full-load-and-cdc&#x27;, # Full load + ongoing replication
TableMappings=json.dumps({
&#x27;rules&#x27;: [
{
&#x27;rule-type&#x27;: &#x27;selection&#x27;,
&#x27;rule-id&#x27;: &#x27;1&#x27;,
&#x27;rule-name&#x27;: &#x27;include-all&#x27;,
&#x27;object-locator&#x27;: {
&#x27;schema-name&#x27;: &#x27;public&#x27;,
&#x27;table-name&#x27;: &#x27;%&#x27;
},
&#x27;rule-action&#x27;: &#x27;include&#x27;
}
]
})
)
print(&quot;Created DMS replication task&quot;)</code></pre>
<h3>Pattern 2: Connection Pooling</h3>
<p><strong>Use case</strong>: Manage database connections efficiently</p>
<pre><code class="lang-python">import psycopg2
from psycopg2 import pool
# Create connection pool
db_pool = psycopg2.pool.SimpleConnectionPool(
minconn=1,
maxconn=20,
host=&#x27;myapp-db.abc123.us-east-1.rds.amazonaws.com&#x27;,
port=5432,
database=&#x27;myapp&#x27;,
user=&#x27;dbadmin&#x27;,
password=&#x27;SecurePassword123!&#x27; # Example only - use AWS Secrets Manager in production
)
def execute_query(query, params=None):
&quot;&quot;&quot;Execute query using connection from pool&quot;&quot;&quot;
conn = None
try:
# Get connection from pool
conn = db_pool.getconn()
cursor = conn.cursor()
# Execute query
cursor.execute(query, params)
# Fetch results
if cursor.description:
results = cursor.fetchall()
else:
results = None
# Commit transaction
conn.commit()
return results
except Exception as e:
if conn:
conn.rollback()
raise e
finally:
# Return connection to pool
if conn:
db_pool.putconn(conn)
# Lambda function with connection pooling
connection_pool = None
def lambda_handler(event, context):
&quot;&quot;&quot;Lambda with persistent connection pool&quot;&quot;&quot;
global connection_pool
# Initialize pool once (outside handler reuses)
if not connection_pool:
connection_pool = create_connection_pool()
# Use pooled connection
results = execute_query_pooled(connection_pool, &quot;SELECT * FROM users LIMIT 10&quot;)
return {
&#x27;statusCode&#x27;: 200,
&#x27;body&#x27;: json.dumps({&#x27;users&#x27;: results})
}</code></pre>
<h3>Pattern 3: DynamoDB Batch Operations</h3>
<p><strong>Use case</strong>: Efficient bulk reads/writes</p>
<pre><code class="lang-python">def batch_write_items(table_name, items):
&quot;&quot;&quot;Batch write up to 25 items at a time&quot;&quot;&quot;
dynamodb = boto3.resource(&#x27;dynamodb&#x27;)
table = dynamodb.Table(table_name)
# DynamoDB limits batch to 25 items
with table.batch_writer() as batch:
for item in items:
batch.put_item(Item=item)
print(f&quot;Batch wrote {len(items)} items&quot;)
def batch_get_items(table_name, keys):
&quot;&quot;&quot;Batch get up to 100 items at a time&quot;&quot;&quot;
dynamodb = boto3.resource(&#x27;dynamodb&#x27;)
response = dynamodb.batch_get_item(
RequestItems={
table_name: {
&#x27;Keys&#x27;: keys,
&#x27;ConsistentRead&#x27;: True
}
}
)
items = response[&#x27;Responses&#x27;][table_name]
# Handle unprocessed keys
while response.get(&#x27;UnprocessedKeys&#x27;):
response = dynamodb.batch_get_item(
RequestItems=response[&#x27;UnprocessedKeys&#x27;]
)
items.extend(response[&#x27;Responses&#x27;][table_name])
return items</code></pre>
<h3>Pattern 4: Database Backup and Restore</h3>
<p><strong>Use case</strong>: Point-in-time recovery and snapshots</p>
<pre><code class="lang-python">def create_rds_snapshot(db_instance_id):
&quot;&quot;&quot;Create manual snapshot&quot;&quot;&quot;
snapshot_id = f&quot;{db_instance_id}-{datetime.utcnow().strftime(&#x27;%Y%m%d-%H%M%S&#x27;)}&quot;
response = rds.create_db_snapshot(
DBSnapshotIdentifier=snapshot_id,
DBInstanceIdentifier=db_instance_id,
Tags=[
{&#x27;Key&#x27;: &#x27;Type&#x27;, &#x27;Value&#x27;: &#x27;manual&#x27;},
{&#x27;Key&#x27;: &#x27;CreatedBy&#x27;, &#x27;Value&#x27;: &#x27;automation&#x27;}
]
)
print(f&quot;Creating snapshot: {snapshot_id}&quot;)
return snapshot_id
def restore_from_snapshot(snapshot_id, new_instance_id):
&quot;&quot;&quot;Restore database from snapshot&quot;&quot;&quot;
response = rds.restore_db_instance_from_db_snapshot(
DBInstanceIdentifier=new_instance_id,
DBSnapshotIdentifier=snapshot_id,
DBInstanceClass=&#x27;db.t3.medium&#x27;,
PubliclyAccessible=False,
MultiAZ=True
)
print(f&quot;Restoring {new_instance_id} from {snapshot_id}&quot;)
def point_in_time_restore(source_db_id, target_db_id, restore_time):
&quot;&quot;&quot;Restore to specific point in time&quot;&quot;&quot;
response = rds.restore_db_instance_to_point_in_time(
SourceDBInstanceIdentifier=source_db_id,
TargetDBInstanceIdentifier=target_db_id,
RestoreTime=restore_time, # datetime object
DBInstanceClass=&#x27;db.t3.medium&#x27;
)
print(f&quot;Restoring {target_db_id} to {restore_time}&quot;)</code></pre>
<hr>
<h2>Quick Reference</h2>
<h3>Database Service Selection</h3>
<p>| Use Case | Service | Type | Best For | |----------|---------|------|----------| | Relational, ACID | RDS | SQL | Structured data, transactions | | Key-value, high scale | DynamoDB | NoSQL | Serverless, millisecond latency | | Caching, sessions | ElastiCache | In-memory | Performance optimization | | Variable workload | Aurora Serverless | SQL | Cost optimization | | Graph data | Neptune | Graph | Relationships, social networks | | Time series | Timestream | Time series | IoT, metrics, logs |</p>
<h3>RDS Instance Sizing</h3>
<pre><code>Workload Type | Instance Class | Example | vCPU | RAM
-------------------|----------------|---------------|------|-------
Dev/test | db.t3.micro | db.t3.micro | 2 | 1 GB
Small production | db.t3.medium | db.t3.medium | 2 | 4 GB
Medium production | db.m5.large | db.m5.large | 2 | 8 GB
Large production | db.r5.xlarge | db.r5.xlarge | 4 | 32 GB
Memory-intensive | db.r5.4xlarge | db.r5.4xlarge | 16 | 128 GB</code></pre>
<h3>Key Guidelines</h3>
<pre><code>✅ DO: Enable Multi-AZ for production RDS instances
✅ DO: Use read replicas to scale read traffic
✅ DO: Enable automated backups (7-35 days retention)
✅ DO: Use connection pooling for Lambda functions
✅ DO: Enable encryption at rest and in transit
✅ DO: Use IAM database authentication when possible
✅ DO: Monitor performance with CloudWatch
❌ DON&#x27;T: Use DynamoDB scans for large tables (use queries)
❌ DON&#x27;T: Expose databases publicly (use VPC endpoints)
❌ DON&#x27;T: Ignore read replica lag for critical queries
❌ DON&#x27;T: Use provisioned capacity without monitoring
❌ DON&#x27;T: Store large objects in DynamoDB (use S3 + pointers)</code></pre>
<hr>
<h2>Anti-Patterns</h2>
<h3>Critical Violations</h3>
<pre><code class="lang-python"># ❌ NEVER: Create new connection per Lambda invocation
def lambda_handler(event, context):
conn = psycopg2.connect(
host=&#x27;db.example.com&#x27;,
database=&#x27;myapp&#x27;,
user=&#x27;dbadmin&#x27;,
password=&#x27;password&#x27;
)
# New connection every time = connection exhaustion
# ✅ CORRECT: Reuse connection across invocations
connection = None
def lambda_handler(event, context):
global connection
if not connection or connection.closed:
connection = psycopg2.connect(...)
# Reuse connection
cursor = connection.cursor()
cursor.execute(&quot;SELECT * FROM users&quot;)</code></pre>
<p>❌ <strong>New connection per invocation</strong>: Exhausts database connections, high latency</p>
<p>✅ <strong>Correct approach</strong>: Initialize outside handler, reuse across warm invocations</p>
<h3>Common Mistakes</h3>
<pre><code class="lang-python"># ❌ Don&#x27;t scan entire DynamoDB table
response = table.scan()
items = response[&#x27;Items&#x27;]
# Consumes read capacity, expensive, slow
# ✅ Correct: Use query with key condition
response = table.query(
IndexName=&#x27;email-index&#x27;,
KeyConditionExpression=Key(&#x27;email&#x27;).eq(user_email)
)
items = response[&#x27;Items&#x27;]
# Efficient, targeted read</code></pre>
<p>❌ <strong>DynamoDB scan</strong>: High latency, expensive, consumes capacity</p>
<p>✅ <strong>Better</strong>: Use query with partition key, add GSI if needed</p>
<hr>
<h2>Related Skills</h2>
<ul><li><code>aws-lambda-functions.md</code> - Lambda integration with databases</li><li><code>aws-storage.md</code> - S3 for database backups and large objects</li><li><code>aws-networking.md</code> - VPC endpoints for private database access</li><li><code>aws-iam-security.md</code> - IAM database authentication and permissions</li></ul>
<hr>
<p><strong>Last Updated</strong>: 2025-10-25 <strong>Format Version</strong>: 1.0 (Atomic)</p>
<footer>
<div class="fmap">
<div><b>Build</b>
<a href="https://hanzo.app">hanzo.app</a> app builder
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
<div><b>Run</b>
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
<div><b>Account</b>
<a href="https://hanzo.id">hanzo.id</a> sign in
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
<div><b>Company</b>
<a href="https://hanzo.ai">hanzo.ai</a> canonical
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
</div>
<div class="fend"><a href="/cloud-aws-databases.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
</footer>
</div></body></html>