Package: ec2-clone
EC2 CloneClone EC2 instances maintaining configuration and data.Installationpip install ec2-cloneConfirm installation withec2-clone --helpUsage + CommandsCommandDescriptionreplace-instanceClone instance and terminate the source instanceclone-instanceClone instance without terminating the source instancecreate-amiCreate AMI from source instancecreate-settings-jsonCreate instance JSON file from source instancecreate-launch-templateCreate launch template from source instanceRun asec2-clone <command> --region <region> --instance-id <instance-id>--instance-idand--regionare required for all commands.Replace InstanceUseful if a perfect copy of an instance is required. This includes private IP addresess and prefixes along with all other instance configuration.Exampleec2-clone replace-instance --region eu-west-1 --instance-id i-12345678UsageUsage: ec2-clone replace-instance [OPTIONS]

  Clone instance and terminate the source instance

Options:
  --settings-input TEXT           Instance settings input file
  -l, --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Log level as string
  --yes                           Assume yes to all prompts
  -r, --region TEXT               Region string in long format, e.g. eu-west-1
                                  [required]
  -i, --instance-id TEXT          Instance ID  [required]
  --ami-name TEXT                 Name used when creating new AMI
  --ami-suffix TEXT               Suffix used when creating new AMI. Full name
                                  will be \{instance-name\}\{suffix\}
  -a, --ami-id TEXT               AMI to use for new instances instead of
                                  creating a new one
  --instance-type TEXT            Override instance type
  --root-volume-size INTEGER      Size of new instances root volume in GB. If
                                  not set, root volume will be increased based
                                  on instance type to accomodate RAM for
                                  hibernation
  --encrypt-root-volume           Encrypt root volume
  --kms-key-id INTEGER            KMS key ID to use for root volume
                                  encryption. AWS EBS default key used if not
                                  specified
  --enable-hibernation            Increase root volume size, encrypt root
                                  volume and enable hibernation
  --help                          Show this message and exit.Clone InstanceUseful if the private IP address of an instance does not need to be maintained.Exampleec2-clone clone-instance --region eu-west-1 --instance-id i-12345678UsageUsage: ec2-clone clone-instance [OPTIONS]

  Clone instance without terminating the source instance

Options:
  --private-ip TEXT               Override instance private IP
  --ipv4-prefix TEXT              Override instance IPv4 prefix
  --settings-input TEXT           Instance settings input file
  --instance-name TEXT            Name used when creating new instance
  --instance-suffix TEXT          Suffix used when creating new instance. Full
                                  name will be \{instance-name\}\{suffix\}
  -l, --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Log level as string
  --yes                           Assume yes to all prompts
  -r, --region TEXT               Region string in long format, e.g. eu-west-1
                                  [required]
  -i, --instance-id TEXT          Instance ID  [required]
  --ami-name TEXT                 Name used when creating new AMI
  --ami-suffix TEXT               Suffix used when creating new AMI. Full name
                                  will be \{instance-name\}\{suffix\}
  -a, --ami-id TEXT               AMI to use for new instances instead of
                                  creating a new one
  --instance-type TEXT            Override instance type
  --root-volume-size INTEGER      Size of new instances root volume in GB. If
                                  not set, root volume will be increased based
                                  on instance type to accomodate RAM for
                                  hibernation
  --encrypt-root-volume           Encrypt root volume
  --kms-key-id INTEGER            KMS key ID to use for root volume
                                  encryption. AWS EBS default key used if not
                                  specified
  --enable-hibernation            Increase root volume size, encrypt root
                                  volume and enable hibernation
  --help                          Show this message and exit.Create AMIWill only stop an instance and create an AMI. This step is performed automatically when running all other commands.Exampleec2-clone create-ami --region eu-west-1 --instance-id i-12345678UsageUsage: ec2-clone create-ami [OPTIONS]

  Create AMI from source instance

Options:
  -l, --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Log level as string
  --yes                           Assume yes to all prompts
  -r, --region TEXT               Region string in long format, e.g. eu-west-1
                                  [required]
  -i, --instance-id TEXT          Instance ID  [required]
  --ami-name TEXT                 Name used when creating new AMI
  --ami-suffix TEXT               Suffix used when creating new AMI. Full name
                                  will be \{instance-name\}\{suffix\}
  --help                          Show this message and exit.Create Settings JSONUseful for dumping only the relevant instance settings that are required forrun_instancesAPI call. If you need to modify more settings than are provided by the default CLI options you can use this command to generate a file to use as input, seeOverridesbelow.Exampleec2-clone create-settings-json --region eu-west-1 --instance-id i-12345678 --output settings.jsonUsage: ec2-clone create-settings-json [OPTIONS]

  Create instance JSON file from source instance

Options:
  -o, --output-file TEXT          Output file when dumping settings
  --private-ip TEXT               Override instance private IP
  --ipv4-prefix TEXT              Override instance IPv4 prefix
  -l, --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Log level as string
  --yes                           Assume yes to all prompts
  -r, --region TEXT               Region string in long format, e.g. eu-west-1
                                  [required]
  -i, --instance-id TEXT          Instance ID  [required]
  --ami-name TEXT                 Name used when creating new AMI
  --ami-suffix TEXT               Suffix used when creating new AMI. Full name
                                  will be \{instance-name\}\{suffix\}
  -a, --ami-id TEXT               AMI to use for new instances instead of
                                  creating a new one
  --instance-type TEXT            Override instance type
  --root-volume-size INTEGER      Size of new instances root volume in GB. If
                                  not set, root volume will be increased based
                                  on instance type to accomodate RAM for
                                  hibernation
  --encrypt-root-volume           Encrypt root volume
  --kms-key-id INTEGER            KMS key ID to use for root volume
                                  encryption. AWS EBS default key used if not
                                  specified
  --enable-hibernation            Increase root volume size, encrypt root
                                  volume and enable hibernation
  --help                          Show this message and exit.Create Launch TemplateUseful if you would like to use the AWS GUI to modify the instance settings before confirming the launch.
As this method is not fully automated it can't perform the following:Move secondary network interfacesTag VolumesTODO - It is possible to tag volumes if there are tags (both key and values) that are shared between all volumesMove EIPExampleec2-clone create-launch-template --region eu-west-1 --instance-id i-12345678UsageUsage: ec2-clone create-launch-template [OPTIONS]

  Create launch template from source instance

Options:
  --private-ip TEXT               Instance settings input file
  --ipv4-prefix TEXT              Override instance IPv4 prefix
  --template-name TEXT            Name used when creating launch template
  --template-suffix TEXT          Suffix used when creating launch template.
                                  Full name will be \{instance-
                                  name\}\{suffix\}
  -l, --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Log level as string
  --yes                           Assume yes to all prompts
  -r, --region TEXT               Region string in long format, e.g. eu-west-1
                                  [required]
  -i, --instance-id TEXT          Instance ID  [required]
  --ami-name TEXT                 Name used when creating new AMI
  --ami-suffix TEXT               Suffix used when creating new AMI. Full name
                                  will be \{instance-name\}\{suffix\}
  -a, --ami-id TEXT               AMI to use for new instances instead of
                                  creating a new one
  --instance-type TEXT            Override instance type
  --root-volume-size INTEGER      Size of new instances root volume in GB. If
                                  not set, root volume will be increased based
                                  on instance type to accomodate RAM for
                                  hibernation
  --encrypt-root-volume           Encrypt root volume
  --kms-key-id INTEGER            KMS key ID to use for root volume
                                  encryption. AWS EBS default key used if not
                                  specified
  --enable-hibernation            Increase root volume size, encrypt root
                                  volume and enable hibernation
  --help                          Show this message and exit.Standard UsageIn standard operation, all instance settings will be copied across aside from a short number of rarely used parameters. (see Limitations below)Ensure required permissions to relaunch instance are present.Including permissions forVolumesSnapshotsAMIsEIPsNetwork InterfacesKMS KeysInstance ProfilesConfigure AWS_ Environment VariablesAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYetc...Runec2-clone <command>following usage from above.Enable HibernationVerify instance AMI supports hibernation (this can't be reliably confirmed programmatically)Windows AMI RequirementsLinux AMI RequirementsFollow standard usage, but run with--enable-hibernationOverridesStandard operation allows for overriding common instance settings via the CLI. If further overrides are required a settings file can be used. The settings file will be passed directly to the run_instances API call allowing for full control over the new instance configuration.clone-instance,replace-instanceandcreate-launch-templatecan all take a file as input using--settings-input. The file is in JSON format, all possible parameters can be foundhere.Generating settingsOften only a couple of parameters need overriding. The following workflow will generate a file containing the current instance settings. You can override only the values necessary before providing the modified file as input.Runec2-clone create-settings-jsonA file will be generated holding the configuration that would have been used to launch the new instance.Modify the generated file to your likingRunec2-clone clone-instance|replace-instance|create-launch-template --settings-input <file>pointing to the modified file.LimitationsIn standard operation the following fields will not be copied between instances.Ipv6 Address countIpv6 AddressesKernelIdRamDiskIdAdditionalInfoLaunchTemplateUserDataWhen using clone-instanceMultiple private IP addresses on the primary nicMultiple Ipv4 prefixes on thee primary nic