This repo contains bash scripts to transfer an EC2 instance from one AWS account (Account A) to another (Account B) using AMI sharing.
- Account A: Create an AMI from an EC2 instance and share it with Account B.
- Account B: Launch a new EC2 instance using the shared AMI.
Run this on Account A. It:
- Creates an AMI from a running EC2 instance
- Waits until the AMI is available
- Shares the AMI and its snapshot with Account B
Run this on Account B. It:
- Creates a key pair (if missing)
- Creates a security group allowing SSH
- Finds a default VPC/subnet
- Launches a new EC2 instance using the shared AMI
- AWS CLI configured (
aws configure) - Necessary IAM permissions to manage EC2, AMIs, and Snapshots
bash account-a-create-and-share.sh- Save the printed
AMI_ID.
- Update the
AMI_IDinaccount-b-receive-and-launch.sh - Run the script:
bash account-b-receive-and-launch.sh- This script uses the default VPC/subnet. Update if needed.
- SSH is enabled from
0.0.0.0/0for demonstration. For production, restrict it. - Ensure snapshots are unencrypted, or share the KMS key if used.
- You cannot directly transfer an EC2 instance between accounts β AMI sharing is the standard way to clone and launch it on another account.
MIT License