Search code examples
amazon-web-servicesamazon-ec2autoscalingzone

Launch EC2 Instances in autoscaling group in the same availability zone


I have written a cloudformation template for launching my stack. My requirement is to have all the instances to be in the same Availability Zone (AZ) rather than being in multiple AZs. I am using autoscaling group and hence I am unable to launch instances in the same AZ.

If instances launch on different AZs I cannot migrate persistent docker containers from one instance to another as flocker uses EBS volumes.

Any workaround for this would be a great help.

Thank you.


Solution

  • I think if you specify the Placement group or Subnet in your cloud formation template, you should be able to do it.
    Please refer Placement Group in Ec2 Cloud Formation and Subnet in Cloud Formation to learn about the exact way to specify these.
    If you specify a placement group for your instances, they will be created in the same placement group in same Availability Zone (AZ). If you specify subnet, they will be created in the same subnet of the same AZ.

    Also, if your autoscaling group is restricted to a single AZ, even that should work. See Autoscaling Group CloudFormation