Greetings!
Recently I needed to export and backup EC2 instances offsite, to later be used in a different lab scenario. I thought this wasn’t actually do-able, until I learned about the aws ec2 create-instance-export-task command.
Using some of my own code, and OpenGPT, I was able to whip up a script that does just that!
The Code:
zveroboy152/EC2-to-S3-Migrator (github.com)
The ‘Script’?
The script is a command-line utility that allows users to export stopped Amazon Elastic Compute Cloud (EC2) instances to an Amazon Simple Storage Service (S3) bucket.
The script begins by prompting to select a region for scanning for instances. Then asked to enter the name of an S3 bucket, and the script lists the stopped EC2 instances in the selected region. Then it asks to confirm whether they want to continue and export the listed instances to the S3 bucket.
After confirming, the script creates a configuration file for the export tasks and then retrieves a list of stopped instances in the specified region. It then loops through the list of instances and exports each one to the S3 bucket using the aws ec2 create-instance-export-task command.
Once the loop completes, the script cleans up the export task configuration file and prints a list of the instances that were exported to the S3 bucket.
This script can be useful for those who want to migrate their EC2 instances to S3 for backup or archival purposes. It provides a convenient and automated way to perform this task. It’s saved me a good headache worth of time, and hopefully helps someone else!
Leave a Reply