Skip to content

Shell scripts to transfer an EC2 instance between AWS accounts by creating and sharing AMIs and snapshots.

Notifications You must be signed in to change notification settings

lufutu/ec2-transfer-cross-account

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EC2 Instance Transfer Between AWS Accounts

This repo contains bash scripts to transfer an EC2 instance from one AWS account (Account A) to another (Account B) using AMI sharing.

🧭 Overview

  • 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.

πŸ“¦ Files

account-a-create-and-share.sh

Run this on Account A. It:

  1. Creates an AMI from a running EC2 instance
  2. Waits until the AMI is available
  3. Shares the AMI and its snapshot with Account B

account-b-receive-and-launch.sh

Run this on Account B. It:

  1. Creates a key pair (if missing)
  2. Creates a security group allowing SSH
  3. Finds a default VPC/subnet
  4. Launches a new EC2 instance using the shared AMI

πŸ› οΈ Requirements

  • AWS CLI configured (aws configure)
  • Necessary IAM permissions to manage EC2, AMIs, and Snapshots

πŸš€ How to Use

Step 1: On Account A

bash account-a-create-and-share.sh
  • Save the printed AMI_ID.

Step 2: On Account B

  1. Update the AMI_ID in account-b-receive-and-launch.sh
  2. Run the script:
bash account-b-receive-and-launch.sh

⚠️ Notes

  • This script uses the default VPC/subnet. Update if needed.
  • SSH is enabled from 0.0.0.0/0 for 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.

πŸ“„ License

MIT License

About

Shell scripts to transfer an EC2 instance between AWS accounts by creating and sharing AMIs and snapshots.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages