Using AWS CLI to connect to MySQL on RDS

I messing around with RDS on Amazon Web Service for a project im working on and realized that there is not a true way to connect to the instance that the database is running on when you stand up a MySQL instance.

After poking around a little bit I came up with this solution and it worked ok for me. Probably needs to be refined and there is probably an easier way also but this worked for me.

First im going to assume you have a MySQL instance running in RDS. Once you have this done you will need to download and unzip the AWS CLI tool to a directory you have access to. > http://aws.amazon.com/developertools/2928

Once you have done this you will need to unzip the package. You can check out the README if you want or you can just do this…
1. copy the credential-file-path.template file and call it something like “cred-file” then chmod it 600
2. vi cred-file fill in the AWSAccessKeyId and AWSSecretKey values. You can get these values from IAM control panel in AWS under your user. If you are lost on that there’s a handy tool called Google. 🙂
3. You will need to set AWS_RDS_HOME in your path
4. Make sure JAVA_HOME is set in your path

Once you have followed these steps you can now try it out…
Do: $AWS_RDS_HOME/bin/rds-describe-db-instances --aws-credential-file cred-file --headers
Hopefully your formatting will be better than what you see here but you should see something similar to this:

DBINSTANCE DBInstanceId Created Class Engine Storage Master Username Status Endpoint Address Port AZ SecAZ Backup Retention Multi-AZ Version License Publicly Accessible Storage Type
DBINSTANCE blah 2014-10-15T17:36:01.553Z db.t1.micro mysql 5 blah available blah.czbrj4wkmqs3.us-east-1.rds.amazonaws.com 3306 us-east-1b us-east-1a 7 y 5.6.19 general-public-license y gp2
SECGROUP Name Status
SECGROUP default active
PARAMGRP Group Name Apply Status
PARAMGRP default.mysql5.6 in-sync
OPTIONGROUP Name Status
OPTIONGROUP default:mysql-5-6 in-sync

Now you have tested and know you can access your MySQL db in RDS.

Error with chef-solo installs: block in from_file

I have found that when you run into an error like this, it helps if you use “sudo”. 🙂 the error is slightly misleading. I kept looking at the code on line 22 and could not figure out what was so wrong. After i took a break and came back to this I noticed further down in package.rb this bit of code:

template "#{node['php']['conf_dir']}/php.ini" do
 source "php.ini.erb"
 owner "root"
 group "root"
 mode "0644"
 variables(:directives => node['php']['directives'])
end

That’s when I realized I should be running this as sudo…worked like a charm. Live and learn.

Here’s the original error:

[seth@lab001 chef-repo]$ chef-solo -c solo.rb -j php.json
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
Converging 7 resources
Recipe: php::package
 * package[php] action install
================================================================================
Error executing action `install` on resource 'package[php]'
================================================================================

Chef::Exceptions::Exec
----------------------
 returned 1, expected 0

Resource Declaration:
---------------------
# In /home/seth/chef-repo/cookbooks/php/recipes/package.rb
22: package pkg do
 23: action :install
 24: end
 25: end

Compiled Resource:
------------------
# Declared in /home/seth/chef-repo/cookbooks/php/recipes/package.rb:22:in `block in from_file'
package("php") do
 action [:install]
 retries 0
 retry_delay 2
 package_name "php"
 version "5.3.3-23.el6_4"
 cookbook_name :php
 recipe_name "package"
end

[2013-09-23T13:36:49-04:00] ERROR: Running exception handlers
[2013-09-23T13:36:49-04:00] ERROR: Exception handlers complete
[2013-09-23T13:36:49-04:00] FATAL: Stacktrace dumped to /home/seth/chef-repo/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-09-23T13:36:49-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)