AWS: Copying AMI across accounts

Copying AWS AMI across accounts require a lot of manual steps. If you do from UI, you will need to share the images, then share the relevant snapshots, then go to the new account console to copy the AMI to your account.

If you have to do it for 100 AMIs, then surely doing manually will not scale. So i write a small script to do the job for me.

Below is my script that allows you to mass copy AMIs from one account to another account based on pattern. You will need to edit to fill in the necessary values: your source account, your target account, and also AWS profile for the source account and the target account as well. awscli and jq are required for the script to work.

The script will search for the AMIs of your source accounts, filter by given pattern, then share the matched AMI and relevant snapshots, and finally copy to the final account.

I have to split the script into two scripts because xargs requires a bash script. I tried export -f but may be I am using Mac so it does not work correctly. Anyway, there is room to improve.

It works well for my migration. I hope it will be helpful for someone 😀

Written by

I write, so I learn.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store