Adding Spot Instances to the Security Group of an RDS Instance - amazon-ec2

I have an RDS MySQL persistant instance, and I am trying to run spot instances which are created once every 8 hours and then destroyed.
The issue I am having is that I don't understand how can I add those spot instances which have dynamic IPs to the security group of my RDS Instance in order to let them perform queries,etc.
Should I grab the IP as soon as the spot instance is created and the add it to the security group of the RDS instance each time a new spot instances is created? Also destroy it every time the spot instance is terminated?
Any tip on what approach to take will be much appreciated!
Thanks!

Assuming that both your spot instances and RDS are in the same region: when setting up an RDS security group, you can also allow machines in EC2 security groups to connect to your RDS machine. Simply add all your spot instances to a EC2 security group and grant access to RDS for this security group.
If your RDS and spot instances are in different regions, you could use the AWS API or an AWS API client like boto for Python to add the IPs automatically.

Related

How to create a bash script for autoscaling EC2 instances given the work volume of a SQS?

I created a bash script with aws-cli that sends 1000 messages using SQS, now I want to create another one that runs in parallel and creates and destroys EC2 instances given this condition:
Checks every 15 seconds: if (((ApproximateNumberOfMessages + 9)/10) - N running instances) > 0 creates an instance, else destroys an instance.
My first problem is that I don't know how to connect my SQS queue to a EC2 instance so it can process these messages. I tried following this tutorial: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-sending-messages-from-vpc.html, but I don't want to use a private VPC and security groups so I was wondering if there is a way to make it easier.
My questions are: Is it possible to do it just using a bash script instead of CloudWatch and Autoscaling Groups? How do I create a EC2 instance that is ready to process these messages?
When you create an EC2 instance, it automatically gets an Elastic Network Interface (ENI, a virtual network card) for which AWS automatically assigns either a default security group, either another user created security group. You can not detach the default ENI, also you cannot have an ENI without a security group. Moreover, EC2 instances have to run inside a VPC, which can be private of public. Nevertheless, if you work with EC2 instances, you have to deal with security groups as well.
Is it possible to do it just using a bash script instead of CloudWatch and Autoscaling Groups?
It might be possible, but you will find yourself reinventing the wheel. Autoscaling does more than just adding/removing instances based on some condition. For example, it also makes sure that your instances are replaced if they become unhealthy or if they are terminated for some reason. For more info see AWS ASG FAQ.
How do I create a EC2 instance that is ready to process these messages?
You can't just start an instance and expect to process your messages. You need to have some code or some kind software deployed to it and configured to poll messages from your queues.

Doubts on moving RDS instance from EC2-Classic to VPC

I need to move RDS oracle instance from EC2-Classic to a VPC, i have some important questions not found on AWS docs:
Is there any downtime ? If so, how much?
The database endpoint will change after the migration?
EC2-VPC instances could still using the db endpoint transparently?
If anyone already did this migration i would like to hear the overall experience.
Thanks!

How to update code on multiple EC2 instances?

I created an Elastic Load Balancer in front of two EC2 instances. However, I discovered an issue that requires me to update the code on both EC2 instances.
I can access each instance individually to update code via github, or I could create an AMI to launch a new instance. It's very unfavorable.
How can I synchronize code between the two EC2 instances?
In situations like this either a code pipeline would be helpful OR better yet switch to Elastic Beanstalk.

How to perform autoscaling in ec2 inside a vpc?

I want to perform autoscaling without using CLI tools. I want to do it from the console itself.
The instance is in vpc ? how can i apply the autoscale policy on instance
Any lead is appriciated.
Thanks in advance.
Documentation:
Follow the instructions on how to Set Up an Auto-Scaled and Load-Balanced Application
Notes:
The instance, created outside of AutoScaling Group can be added to Elastic Load Balancer, but will not be monitored or managed by AutoScaling group.
Instance, created outside of AutoScaling Group can be marked as unhealthy by Elastic Load Balancer if the health check fails, but it will not cause AutoScaling Group to spawn a new instance.

How different is an Amazon EC2 RDS DB Instance different from the normal EC2 Instance?

How different is the Amazons RDS DB Instance different from The normal EC2 Instance other than the fact that RDS DB Instance has a Database server running on it?
When an EC2 Instance goes down all the data associated with it also vanishes(when you dont attach an EBS). Is this true for RDS DB Instance as well?
I have already set up my database server with the following: 1 small Instance?(m1.small) with Mysql and attached a 10GB EBS and routed the Mysql Data Directories to EBS.
Is the small Instance of EC2 RDS any Different from the above?
An RDS db instance can be configured to not lose any data during downtime, either planned or unplanned. For unplanned downtime, AWS keeps transaction logs which are replayed automatically on a failover instance. These logs can also be used to get an instance to a specific point in time.
For planned downtime, you create a DB snapshot prior to stopping the instance, and can later start a new instance with the saved snapshot.
RDS is a unmanaged MySQL service, means you only start and load data into it and your ready to go.
Is the small Instance of EC2 RDS any Different from the above?
The small instance of RDS is a 64bit, which support multi AZ failover and pricing obviously is a little expensive compared to EC2 MySQL.
EC2 Mysql needs more administration, but you can setup it up to do replication and you can customize it to have better performance compared to RDS.
See also http://www.dotdeb.org/2010/05/04/mysql-on-amazon-benchmarks-rds-vs-ec2/

Resources