There is a way to encrypt your AWS RDS Amazon Aurora with PostgreSQL compatibility Cluster with no or minimum downtime, but it will take a bit of effort.
You need to take the following steps:
- For the source DB, you have to take snapshot.
- Then copy that snapshot, and check
Enable Encryption
and select Default Encryption Key
or select your Custom AWS KMS CMK
, now you have an encrypted copy of your DB snapshot.
Restore
this encrypted snapshot to the new DB instance, and you can enable Multi-AZ
and add Read Replicas
now or modify them after migration.
- Now you have two DB instances
Encrypted
and Unencrypted
, but the data mismatched as it is a production database.
- We will use AWS DMS to make synchronous replication of data, or ou can use PostgreSQL logical replication with Aurora instead of AWS DMS, it will be better, both will works.
- Go to AWS DMS console, create an AWS DMS task.
- For migration type, choose
Migrate existing data and replicate ongoing changes
.
- For target table preparation mode, choose
Truncate
.
- Under Advanced Task Settings, enable the
awsdms_status
table if you want to verify replication status.
- Run the migration task and wait until all the records are updated. AWS DMS will then determine the size of the data to migrate.
- Then, you need to verify the data in the
Encrypted
DB instance after migration is the same as the Unencrypted
DB instance.
- Check replication status in AWS DMS, by checking the migration task and
awsdms_status
.
- You can now route traffic to the new endpoint.
- For a smooth cutover, use Amazon Route 53 to route traffic by changing the DNS TTL to a short value, and eventually replacing the endpoint names in Route 53.
Now replying to your questions,
- Is there any downtime during the creation of the snapshot assuming there is a lot of data and a snapshot will take time.
According to you cluster setup, you are running a Multi-AZ deployment, automated backups and DB Snapshots are simply taken from the standby to avoid I/O suspension on the primary. Please note that you may experience increased I/O latency (typically lasting a few minutes) during backups for both Single-AZ and Multi-AZ deployments.
- What about the new data that is being written on to the database during the snapshot creation? Is the snapshot creation real-time or I
will lose my new data during the time till the snapshot is being
taken?
You will lose your data written after the snapshot has been taken, so you will use AWS DMS to replicate synchronous data to your encrypted DB instances.
- Is this the only way for me to enable encryption on the production cluster knowing that it will result in some database outage?
Yes this is the only way, but it will result in no or little downtime.