4
votes

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.

2

2 Answers

2
votes

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.

3
votes

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.