Create AWS Launch template from existing AWS EC2 instance of another account

amazon ec2amazon-web-services

How can I create an AWS Launch template from existing AWS EC2 instance of another AWS account?
Something like if the account user can share his configuration file containing details such as AMI, Instance type, Instance details, Storage details, Tags, Security details, etc. of his instance settings and I can just import the file while Launching my new instance and it will create and exact same environment.

Best Answer

Using aws cli, from the first account get the launch template data, and save it to a json file:

aws ec2 get-launch-template-data \
  --instance-id i-0123d646e8048babc \
  --query 'LaunchTemplateData' \
> account1-launch-data.json

And then in the second account, create the template from the json file:

aws ec2 create-launch-template \
  --launch-template-name Account2Template \
  --version-description Account1Copy \
  --launch-template-data file://account1-launch-data.json

You can then use this template to launch the ec2 instance using its launch template id:

aws ec2 run-instances \
  --launch-template LaunchTemplateId=<template id>,Version=1
Related Topic