Skip to content

Instantly share code, notes, and snippets.

@PiotrKuligowski
Created July 29, 2022 09:55
Show Gist options
  • Save PiotrKuligowski/bd632c977344efff8b42cf8778839c4e to your computer and use it in GitHub Desktop.
Save PiotrKuligowski/bd632c977344efff8b42cf8778839c4e to your computer and use it in GitHub Desktop.

AWS RDS Aurora MySQL

AWS RDS Aurora MySQL Cluster (1 instance)

RDS:

  • aurora-test (Regional cluster)
    • aurora-test-instance-1 (Writer instance)

Cluster endpoints:

> nslookup aurora-test.cluster-ro-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance
> nslookup aurora-test.cluster-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance

Instance endpoints:

> nslookup aurora-test-instance-1.cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance

Adding 1st reader node

RDS:

  • aurora-test (Regional cluster)
    • aurora-test-instance-1 (Writer instance)
    • aurora-test-reader (Reader instance)

Cluster endpoints

> nslookup aurora-test.cluster-ro-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 52.49.243.230 --> points to reader instance
> nslookup aurora-test.cluster-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance

Instance endpoints:

> nslookup aurora-test-instance-1.cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance
> nslookup aurora-test-reader.cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 52.49.243.230 --> points to reader instance

Adding 2nd reader node

RDS:

  • aurora-test (Regional cluster)
    • aurora-test-instance-1 (Writer instance)
    • aurora-test-reader (Reader instance
    • aurora-test-reader-2 (Reader instance)

Cluster endpoints:

> nslookup aurora-test.cluster-ro-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 52.49.243.230 --> points to reader instance

> nslookup aurora-test.cluster-ro-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 34.243.226.163 --> points to second reader instance
> nslookup aurora-test.cluster-cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance

Instance endpoints:

> nslookup aurora-test-instance-1.cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 63.34.212.43 --> points to master instance
> nslookup aurora-test-reader.cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 52.49.243.230 --> points to reader instance
> nslookup aurora-test-reader-2.cytaifhqfdcq.eu-west-1.rds.amazonaws.com
...
Address: 34.243.226.163 --> points to second reader instance

Summary

  • cluster endpoint points always to master instance (writer)
  • cluster read only endpoint points to any of reader instances (load balanced)

ASCII

      [M]   [R] [R]
       |     |   |
       |     \___/
write  |       | read
        \_____/
           |
@PiotrKuligowski
Copy link
Author

Terraform Error
The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around
│ this, use the -target argument to first apply only the resources that the count depends on.

My solution maybe not the best but works is to decouple it and not reference needed variable/local/property directly but through remote state

so in XYZ stack

  • i export needed value and in the same stack
  • terraform apply -refresh-only to write value to state
  • I create terraform_remote_state and get value from there
    this way it is decoupled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment