Copying EC2 instance from another region brings the wrong routing table with it

Viewed 317

I've a small problem in that I created an AMI in one AWS region and then copied it to another region. I've used it to fire up instances in the new region but the new instances all have some static routes that relate to the network interface of the previous region and as such the 169.254.169.254 metadata service isn't reachable:

The route print from an instance in the region where I created the AMI is:

  Network Address  Mask                 GW               Met
  169.254.169.254  255.255.255.255      172.31.16.1      15
  169.254.169.250  255.255.255.255      172.31.16.1      15
  169.254.169.251  255.255.255.255      172.31.16.1      15
  169.254.169.249  255.255.255.255      172.31.16.1      15
  169.254.169.123  255.255.255.255      172.31.16.1      15
  169.254.169.253  255.255.255.255      172.31.16.1      15

The region I'm now spinning up instances in has e.g.:

Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0       172.30.1.1    172.30.1.180      15

I could start an instance, modify the routing table with e.g. route change 169.254.169.254 mask 255.255.255.255 172.30.1.1 metric 15 if 3, shut it down, save an AMI, and launch more instances from the new AMI... But is there a way to do all this from outside the instance/in the management panel so I don't have to create another image?

1 Answers

yes you can use ec2 user data for running commands like

route change 169.254.169.254 mask 255.255.255.255 172.30.1.1 metric 15 if 3

directly from the console if the root volume is an EBS volume.

To update the instance user data, you must first stop the instance. If the instance is running, you can view the user data but you cannot modify it.

View and update the instance user data

And then, you can skip the step for saving this as an AMI and use Launch More Like This which creates the AMI under the hood for you.

By default, user data scripts run only during the boot cycle when you first launch an instance. You can update your configuration to ensure that your user data scripts run every time you restart your instance. How can I utilize user data to automatically run a script with every restart of my Amazon EC2 Linux instance?

Launch an instance using parameters from an existing instance

The Launch more like this wizard option does not clone your selected instance; it only replicates some configuration details. To create a copy of your instance, first create an AMI from it, then launch more instances from the AMI.

Or Use EC2 Launch Template with userdata for providing various commands I want to customize the instance with.

AWS::EC2::LaunchTemplate LaunchTemplateData.

Related