The account has hundreds of EC2 instances with EBS volumes that are encrypted with the KMS AWS managed key aws/ebs.
The need to encrypt or re-encrypt EBS volumes is not uncommon, so someone would have developed tools and scripts for it.
To encrypt or re-encrypt an EBS volume that is attached to an EC2 instance, create a snapshot of the volume, create a new volume from the previously created snapshot, detach the original volume from EC2 instance, attach a new volume to EC2 instance with same device name as above.
Given Boto3 and Python are part of my preferred toolset, I decided to leverage the aws_volume_encryption solution as my starting point.
Although developed years ago, the original script remains fully functional, proving its reliability.
The original volume still exits and have some metadata tags added by the script for traceability.
With this improved script, you can (re-)encrypt EBS volumes of any EC2 instance with ease.
If you are encrypting volumes for many instances, you can write another script that reads a CSV file containing EC2 instance information and runs volume_encryption.py on multiple instances in parallel.
This demonstrates how automation and generative AI empower DevOps engineers to tackle complex challenges efficiently.
If your organization’s security policies require that EBS volumes be encrypted, consider using the Amazon EBS encryption by default feature to automatically encrypt any new EBS volumes.