4

I'm new to Elastic Beanstalk and I have a "simple" problem with where the EC2 and RDS instances are created. For a couple of hours now of creating, deleting enviroments and googling for solutions I'm out of ideas.

The problem seems quite simple. I want the EC2 and RDS instances in the same Availability Zone so that I don't have to pay for the traffic between Availability Zones. But it seems the zones in which they are created are random (1a-1c). In the "Configuration" tab I see that under Instances "Availability Zones: Any" is configured. But when I edit the instance configuration there is no option to change it.

The actual zone doesn't matter. Important is only that all instances are created in the same zone.

Thank You.

ssindelar
  • 2,833
  • 1
  • 17
  • 36

2 Answers2

3

The aws:autoscaling:asg:Custom Availability Zones option does not work for modern "VPC" Elastic Beanstalk environments.

You will get the error: Custom Availability Zones option not supported for VPC environments.

Instead, you must limit the subnets that you provide via the aws:ec2:vpc:Subnets option to only specify subnets in the AZ where you want your instances to run.

Shorn
  • 19,077
  • 15
  • 90
  • 168
  • The subnets adjustment can also be made through the console under the Configuration -> VPC section, where AZ, ELB, and EC2 options are provided – user1652110 Apr 10 '17 at 04:15
2

This is possible. You can specify a custom availability zone both for your EC2 instances and your RDS database. You can use .ebextensions to achieve this. Create a directory with name .ebextensions in your app source. Inside this directory create a file with name '01-rds-setup.config'. Config files in this directory are processed in lexicographical order of their name. Assuming this is the only file it will be processed.

To configure the EC2 availability zone use the "Custom Availability Zones" option setting under "aws:autoscaling:asg" namespace. Documentation on this option setting is available here. To configure the RDS availbility zone you can override the properties of the RDS Resource. For more documentation on overriding resource properties read this.

Contents of your file .ebextensions/01-rds-setup.config:

option_settings:
   - namespace: aws:autoscaling:asg
     option_name: Custom Availability Zones
     value: us-west-2a
Resources:
   AWSEBRDSDatabase:
     Type: AWS::RDS::DBInstance
     Properties:
        AvailabilityZone: us-west-2a

Make sure you do not select the Multi-AZ option when launching an Elastic Beanstalk environment with RDS from the console. This should work for your usecase.

Rohit Banga
  • 18,458
  • 31
  • 113
  • 191
  • Thank you. That sounds very promising. When I upload a new version and the RDS server is in a different zone, the old one gets deleted and a new one is set up, right? Because I'm going on a holiday tomorrow it will be quite some time before I can test it. – ssindelar Jul 02 '14 at 07:55
  • I would expect that the RDS gets deleted along with the data and a new RDS launched in the expected availability zone. (Not tested this replacement scenario yet, but the above ebextension should work for a new environment). I would recommend trying on a new environment just to be safe. – Rohit Banga Jul 02 '14 at 07:59
  • Ah forgot that you can upload the application version when creating a new enviroment not just after. – ssindelar Jul 02 '14 at 08:24