How to access MySQL running on an EC2 instance from Lambda? - mysql

Is it possible to use Lambda(triggered by AWS IoT) to read/write to a MySQL server running on an EC2 instance? If so how would you do that? All info I see on internet seems to relate specifically to Amazon RDS rather than EC2 instances.
Thanks, Marcus

You need to connect the Lambda to the subnet where the MySQL server is running. See https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html.
Once that is done, you can connect to it using the server's private IP, as you normally would any MySQL server.

Related

Can AWS RDS be used as a MySQL host only?

Is it possible to use AWS' RDS MySQL solution in tandem with my current file server host? By that, I mean, can I connect to the RDS MySQL server as I am with my hosts current database?
I've tried the AWS documentation but it seems a bit flaky in this area.
Thank you,
Amazon RDS is a database server, just like any other. If you start up an RDS MySQL server, you can connect to it from anything else that can connect to a MySQL server.
The difference is that you do not have direct host access to the RDS server. Meaning, you cannot SSH into it and get a command prompt.
But you can connect to it from any MySQL client, including MySQL Workbench.

Enforce SSH to mysql

I have setup a linux server in Amazon Ec2 with a mysql db in RDS.
Connect from mysql workbench to RDS is going fine with (TCP/IP) or (TCP/IP with SSH).
My question is, how to enforce all connections to RDS must going through linux server? I want to enforce this behaviour because it gives an extra layer of security.
Want to enforce this
Client -> EC2 Linux Server -> RDS
Want to stop this
Client -> RDS
My Ec2 Configuration
My RDS Configuration
untested
Try:
[client]
protocol=tcp
host=<ip address of DB server>
in your my.cnf file. Where the host can only be accessed via ssh.
After playing with it some time, I finally got the desired result by setting the security group id as parameter in the source connection setting. Thanks all.

How Ruby on rails works with Amazon RDS

I have a ruby on rails run on amazon ec2, database is mySQL.
Now I want to use Amazon RDS to backup this database in case the ec2 fails.
I read through the Amazon RDS user guide,it tells how to create a DB instance.
My question is:
1.what is the relation between created DB instance and my ec2 database?
2.When the DB instance "connect" to my ec2, what will happen?
The data used to send to ec2 mySQL server will be send to DB instance?
Is the database totally shifted to DB instance?So before I connect I should creare a same database in DB instance and tell ec2 send data to RDS ever since
3.If not,how the DB instance know the ec2 is down and takeover the data?
EDIT:
(Unsure)Is it that DB instance is just a place to put database.In order to use it,I need to set up database in DB instance,then connect to it by modifying database.yml file(this file tell rails server where the stored data goes).
How Is it possible to tell when the local database stops then at that time switch to DB instance?
There is absolutely no relationship between your EC2 MySQL DB and the RDS DB Instance. So what you are asking for is just not possible.
A better approach I would say is to have only RDS (No need to have MySQL running locally on EC2 instance). RDS takes snapshots regularly. Also, RDS is a managed service, so most of the MySQL administration tasks are handled by AWS and you don't have to worry. And you can rely on RDS snapshots from Backup perspective.

How does one see what data is stored in the RDS database?

Running our app on Amazon RDS. How does one review / inspect data in the database? For example, how can I get a list of articles?
My app is running on Ruby on Rails and on Heroku. One method I thought of, is by running the Heroku console command.
Is there a better way to see what data is stored in the RDS database?
I use MySQL Workbench to view data, run queries, and so on. It connects right up to the Amazon RDS MySQL instance using the regular MySQL settings.
Updated:
Be sure to add the ip address of the computer for which you're connecting to the RDS instance to the access list in RDS. IIRC, by default RDS instances will only accept connections from within AWS.
I was using SequelPro but they don't support ssl. Amazon RDS says something to the effect of having to use SSH to connect your EC2 to your RDS.
This is essentially what was done in the following tutorial which uses MySQL Workbench: http://thoughtsandideas.wordpress.com/2012/05/17/monitoring-and-managing-amazon-rds-databases-using-mysql-workbench/
I had also been using SequelPro before but this tutorial is very clear and I was up and running on MySQL Workbench in just a few minutes.

MySQL on Amazon?

I'd like to have 20 different Amazon EC2 instances that read and write from the same shared location. Is it at all possible?
Also, is it possible to have an instance of MySQL that will be accessible from all 20 Amazon EC2 instances?
You could use Amazon's RDS which offers a managed MySql service which all your instances could access. Otherwise yes of course it is possible to have a single MySql instance running which all your other instances can access in which case you will need to configure MySql to allow remote connections and open the EC2 port (3306 by default) on the database server.
The whole idea of a database server is to provide a shared data repository. If you can get to your single MySQL instance over the network, you shouldn't have a problem.