Elastic Beanstalk: Create EC2 and RDS instances in the same Availibity Zone - amazon-web-services

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.

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.

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.

Related

AWS Python SDK - guarantee that EBS volume and EC instance are in the same availability zone

I am scripting the setup of AWS resources using the Python SDK (boto3). I can create ec2 instances with:
ec2_resource.create_instances( .... )
and a block storage volume with:
ec2_client.create_volume(..., AvailabilityZone = "eu-north-1a")
As indicated I can specify the availability zone for the block storage, however I have not understood how to specify that for the ec2 instance; when looking in the console I generally find that the ec2 instance has been created in another availability zone - e.g. "eu-north-1c", and then instance.attach_volume() fails because they are not in the same availability zone.
What is the correct way to approach this?
I hope you're using boto3 and not the outdated boto library ;-)
By specifying the subnet ID to launch the instance into, you implicitly set the availability zone, because each subnet is located in exactly one availability zone.

Not able to select Availability Zones on AWS Elastic Beanstalk

I created an Elastic Beanstalk environment with custom configuration. I was able to change Availability Zones and placement, and I picked them.
After I created the environment, Elastic Beanstalk complained about
- Stack named 'awseb-e-**********-stack' aborted operation. Current
state: 'CREATE_FAILED' Reason: The following resource(s) failed to
create: [AWSEBInstanceLaunchWaitCondition].
- The EC2 instances failed to communicate with AWS Elastic Beanstalk,
either because of configuration problems with the VPC or a failed EC2
instance. Check your VPC configuration and try launching the
environment again.
I wanted to check out the AZs and placements; however, they are disabled
Why is that disabled? Is there a way to enable it? If so, how?
If you use Elastic Beanstalk with Load Balancer, you need to control Auto Scaling Group under Configuration > Network.
For example, if you just want to deploy on us-east-1b, select a subnet which uses that Availability Zone.

Creation RDS aurora cluster via cloudformation

I am creating a VPC with ec2 instances and 2 subnets and 2 availability zones through a cloudformation template,
I always get the same error when reaching the stage of creating the RDS cluster /
Your subnet group doesn't have enough availability zones for a storage cluster. You must have at least two availability zones to map to a storage cluster.
you can find the templates in this link :
link to templates
I just ran into this same issue and I was definitely using 2 subnets from 2 different AZs. There might be some underlying backend issue... selecting different AZs worked for me. ie - I was trying subnets from us-east-1a and us-east-1b, I switched to using subnets from us-east-1c and us-east-1d and it worked.
I contacted AWS and they told me this is because Aurora is not available on us-east-1b and us-east-1f
There is no documentation about it and they are looking to add these AZs, but in the meantime you'll need to use another AZ
The error which you have posted occurs when your DBSubnetGroup is confined to a single availability zone. I think both of your subnets are getting created in the same AZ.
In the AWS::EC2::Subnet documentation, it is recommended to leave the AZ allocation for subnet to AWS.
Removal of the Availability zone should resolve your issue.
Hope this helps.

Accessing RDS from Elastic Beanstalk, cannot change secuirty groups

I am trying to access an RDS database in a VPC from elastic beanstalk. I tried adding the vpcgroup to the the security group list for elastic beanstalk, which works for a regular ec2 instance, but when I try to do this for the elastic beanstalk security group I get the following error message:
Could not update your security group rules (No changes were made): You may not define rules between a VPC group and a non-VPC group
I have also tried adding the existing security group I use for ec2, which can access the RDS database, to the elastic beanstalk instance, but when I do that it says the security group does not exist. How can I make it so that the elastic beanstalk instance has access to my RDS database? Alternatively, what do I need to put in the config.yml file so that it starts out with my prexisting security group that already has access to the RDS database / VPC?
Security groups are specific to a VPC. It appears that your Elastic Beanstalk environment is in EC2 classic instead of a VPC. The quick solution is to enable Classic Link. The more long-term solution is to rebuild your Elastic Beanstalk environment in your VPC.
To start the instance in an existing vpc you need to add the vpc and subnet to a .config file in .ebextensions. For example:
option_settings:
- namespace: aws:ec2:vpc
option_name: VPCId
value: vpc-IDhere
- namespace: aws:ec2:vpc
option_name: Subnets
value: subnet-IDhere

Define subnets for multi-az elb deployments with boxfuse

I noticed there is already a
-subnet=... The AWS subnet to deploy to (single instance apps only)
parameter but not for ELB-based deployments, yet. Is it already possible to define which vpc/subnets should be used for a deployment?
Currently all subnets of the default VPC are associated with the automatically created auto-scaling groups. The auto-scaling groups will then launch instances across them in a balanced fashion.
Please file a feature request if you need more control: https://github.com/cloudcaptainsh/cloudcaptain/issues