> For the complete documentation index, see [llms.txt](https://awsarch.adot8.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://awsarch.adot8.com/module-6.md).

# Module 6

### All about AWS Databases

{% embed url="<https://awsfdn.adot8.com/module-8>" %}

### Database considerations

| Scalability                    | Storage requirements                                                             | Data characteristics                                         | Durability                                                                   |
| ------------------------------ | -------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------- |
| How much throughput is needed? | Will the database need to be sized in gigabytes, terabytes, or petabytes of data | What is your data model? What are your data access patterns? | What level of data durability, availability, and recoverability is required? |
| Will it scale?                 |                                                                                  | Do you need low latency?                                     | Do regulatory obligations apply?                                             |
|                                |                                                                                  |                                                              |                                                                              |

### Relational and non-relational databases

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FZfDdYx87vx56XFJW4XMi%2Fimage.png?alt=media&amp;token=f8690b9c-868e-4fde-ae6a-9f1a3f0f3d46" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Relational = SQL/Tables ; Non-relational = Objects/JSON documents/fast lol
{% endhint %}

### Amazon Database Options

| Relational Databases                                                                                                                                                                                                                                      | Non-relational databases                                                                                                                                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FCcHIgJsSjVDQCqCHvbvW%2Fimage.png?alt=media&amp;token=77844753-3947-4fb1-a09c-13c546769008" alt="" data-size="original"> | <img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FcYiL58Da5hY6Lo638vWg%2Fimage.png?alt=media&amp;token=1e9088cf-4907-405a-b0d2-b9449c3ca10f" alt="" data-size="original"> |
| :(                                                                                                                                                                                                                                                        | <img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FKqwJBsm5p0bV5dN0tBCn%2Fimage.png?alt=media&amp;token=d001e0a3-743d-44b0-9632-63b5970bcabf" alt="" data-size="original"> |
| :(                                                                                                                                                                                                                                                        | <img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F345O5NnUD1IHgEB1wgXD%2Fimage.png?alt=media&amp;token=230b22d2-ad54-456d-9991-0d185728597e" alt="" data-size="original"> |

### Database Capacity Planning

1. Analyze current storage capacity
2. Predict capacity requirements
3. Determine if horizontal scaling, vertical scaling, or a combination is needed

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2Fx6ERrHSI98jZBN3WszXp%2Fimage.png?alt=media&amp;token=37cf855d-e15c-42c9-8024-8bf837c41024" alt=""><figcaption></figcaption></figure>

### Amazon Relational Database Service (RDS) <img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FPy8AhxUwvSpf6eiOLgLk%2Fimage.png?alt=media&amp;token=96ea6ac2-c2f2-4847-88e2-3fbcc4c7c8fc" alt="" data-size="line">

* Is a managed relational database service to deploy and scale relational databases
* Supports multiple database engines
* Uses Amazon Elastic Block Store (Amazon EBS)volumes for database and log storage

{% hint style="danger" %}
By default the database is **NOT** encrypted. You can only encrypt it while your first provisioning/building the database. You can't encrypt it after its done
{% endhint %}

#### Benefits of RDS

* You don't need to provision your infrastructure or install and maintain database software
* You can scale up or down the compute and memory resources powering your deployment
* You can configure automated backups, database snapshots, and automatic host replacement
* You can isolate your database in your own virtual network

#### RDS Architecture

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FmeheqalTrlwic5klgzg8%2Fimage.png?alt=media&amp;token=878d30e7-5f78-40ae-8fa9-b44762db6232" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FxxQS1cHMLEjvAs3x8RE7%2Fimage.png?alt=media&amp;token=57c732a4-08d0-4491-814a-f2a248c31b2a" alt=""><figcaption></figcaption></figure>

### Amazon Aurora (sub type of RDS)

* Is a relational database management system (RDBMS) built for the cloud with full MySQL and PostgreSQL compatibility
* Is managed by Amazon RDS
* Provides high performance and availability at one-tenth of the cost
* Delivers Multi-AZ deployments with Aurora Replicas

{% hint style="info" %}
Can be serverless, up to 15 read replicas, 100% compatiable
{% endhint %}

#### Aurora clusters

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F4nsEwEyCyvbMb6WZqRtO%2Fimage.png?alt=media&amp;token=69484ab9-7a5f-490b-8e35-c4c464a992cc" alt=""><figcaption></figcaption></figure>

#### Amazon RDS use case:

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FuXeIZ5SqQkgIG9qGP9E3%2Fimage.png?alt=media&amp;token=c7a634a4-3b2e-4f6a-be2f-47929765d7a3" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
We have tables, fixed properties and a strict format
{% endhint %}

#### RDS Best practices

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F428MKMvXt5cw7O1zkDyH%2Fimage.png?alt=media&amp;token=88c17463-f745-4127-bc1b-e99919dbbd80" alt=""><figcaption></figcaption></figure>

### Amazon RDS Proxy

* Fully managed and highly available

| More scalable                                                          | More resilient                                                                                                            | More secure                                                               |
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| Pools and shares database connections for improved application scaling | Reduces database failover times for Aurora and Amazon RDS databases by up to 66 percent for Amazon RDS Multi-AZ databases | Enforces IAM authentication and stores credentials in AWS Secrets Manager |

#### Connection Pooling for Improved Scalability

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FGCKqWQMIjzkVvDjuFOox%2Fimage.png?alt=media&amp;token=7f2392aa-c79e-4bf6-8deb-77fba47c50bf" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
We can store database user credentials in **Secrets Manager.** The application should be the only principal that can read the credentials. This prevents source code leakage to contain credentials
{% endhint %}

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FQkEULKMZDozH8Tq6icdG%2Fimage.png?alt=media&amp;token=f4d25b02-1179-4432-9848-7582158b2695" alt=""><figcaption></figcaption></figure>

#### Backing up data in RDS

Two options backups and snapshots:

* Backup
  * Restore a database instance to a specific point in time
  * Daily during your backup window (transaction logs are captured every 5 minutes)
  * The default is 7 days but it can be set to up to 35 days. The backups can be automatically deleted after any retention period
  * Cannot be shared (needs to be copied to a manual snapshot first)
* Database Snapshots
  * Back up a database instance in a known state, and then restore it to that specific state.
  * User-initiated (as frequently as the user chooses)
  * Kept until the user explicitly deletes it
  * Can be shared (shared snapshots can be copied by other AWS accounts)

#### RDS encryption for backups

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FfrLwczhbWxN286NHd9Wx%2Fimage.png?alt=media&amp;token=9191d547-b806-414e-a01f-28dddfd8bc21" alt=""><figcaption></figcaption></figure>

### Amazon DynamoDB

* Is a fully managed, serverless, NoSQL database
* Supports key-value and document data models
* Delivers millisecond performance and can automatically scale tables to adjust for capacity
* Is used for developing applications, and mission-critical workloads that prioritize speed, scalability, and data durability

{% hint style="info" %}
JSON document; has a partition and sort key
{% endhint %}

#### Use cases

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FUIwLKbzj7OES2FdShaQc%2Fimage.png?alt=media&amp;token=025ee366-68d8-4304-acbc-512d5153d841" alt=""><figcaption></figcaption></figure>

#### Features

* Serverless performance with limitless scalability
  * Secondary indexes provide flexibility on how to access your data.
  * Amazon DynamoDB Streams is ideal for an event-driven architecture.
  * Multi-Region, multi-active data replication with global tables
* Built-in security and reliability
  * DynamoDB encrypts all customer data at rest by default.
  * Point-in-time recovery protects data from accidental operations

#### Structure

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FtxBjxoDHPEsTIShKtNH0%2Fimage.png?alt=media&amp;token=555cfe49-77e5-493d-989e-3c549084d6f4" alt=""><figcaption></figcaption></figure>

#### Example

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FZTEVLC70g0TyVHIEcdZg%2Fimage.png?alt=media&amp;token=ee702566-a550-4d92-8152-9f207bdead95" alt=""><figcaption></figcaption></figure>

#### Multi-region Replication

Global tables provide a multi-region, multi-active database for fast local read and write performance for global applications

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F9wfPzu4eQjYW7nkAd2gK%2Fimage.png?alt=media&amp;token=2f6b406a-0663-426c-a901-e227f11d10a9" alt=""><figcaption></figcaption></figure>

#### Best practices

| Preventative                                              | Detective                                                   |
| --------------------------------------------------------- | ----------------------------------------------------------- |
| Use IAM roles to authenticate access                      | Use AWS CloudTrail to monitor AWS managed AWS KMS key usage |
| Use IAM policies for DynamoDB base authorization          | Monitor DynamoDB operations by using CloudTrail             |
| Use IAM policy conditions for fine-grained access control | Monitor DynamoDB configuration with AWS Config              |
| Use a VPC endpoint and policies to access DynamoDB        | Monitor DynamoDB compliance with AWS Config rules.          |

### Amazon Redshift

* Is a fully managed, cloud-based data warehousing service designed to handle petabyte-scale analytics workloads&#x20;
* Achieves optimum query performance with columnar storage
* Has an Amazon Redshift Serverless option
* Is used for online analytics processing (OLAP)

#### AWS fully managed purpose-built database options

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FE05Ry4L9OQZElFdzxCq3%2Fimage.png?alt=media&amp;token=eff2cccf-6a97-4092-90a7-7583fa86b23b" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
A ledger database can be used for keeping transactions/history of data (e.g. credit card)
{% endhint %}

Make sure that...

* You have suitable workloads
* Correct data model
* Look over feautes and benefits
* Review common use cases

before choosing a database :doughnut:

### AWS DMS&#x20;

Migrate an on-prem database to a AWS database

* Is a managed migration and replication service
* Helps move existing database and analytics workloads to and within AWS
* Supports most widely used commercial and open source databases&#x20;
* Replicates data on demand or on a schedule to replicate changes from a source

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FFvuwDlpHnt0CGI3WDbNC%2Fimage.png?alt=media&amp;token=a603dda6-721e-424e-a9c0-a81f96445392" alt=""><figcaption></figcaption></figure>

#### Tools to migrate between different database engines

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F3e90wS6pkARKsGRv212a%2Fimage.png?alt=media&amp;token=a1d01ad5-8fa6-4e86-9817-fb75bab30140" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FXh3YIHzlJd615g7XxT75%2Fimage.png?alt=media&amp;token=d8625c90-a362-4a8b-84b8-1bba15604685" alt=""><figcaption></figcaption></figure>

#### &#x20;AWS DMS replicates data from a database into a data lake

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FVjtWhnGHV0ktauGwsbG4%2Fimage.png?alt=media&amp;token=a2a911da-e195-48e4-913b-5ac9c4037ea5" alt=""><figcaption></figcaption></figure>
