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
copy-snapshot.sh 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.
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 😀