Permalink
Browse files

Create RDS instance, drop and create DB with data

  • Loading branch information...
1 parent 1edeaca commit 435c76738689b24034446578d2707d5304544a89 @adomokos committed May 30, 2016
Showing with 41 additions and 0 deletions.
  1. +28 −0 Makefile
  2. +10 −0 resources/schema.sql
  3. +3 −0 resources/seed.sql
View
@@ -1,5 +1,7 @@
OSXDIR=hello-1.0.0-osx
LAMBDADIR=hello-1.0.0-linux-x86_64
+DBPASSWD=Kew2401Sd
+DBNAME=awslambdaruby
THIS_FILE := $(lastword $(MAKEFILE_LIST))
@@ -76,6 +78,32 @@ invoke: ## Invoke the AWS Lambda in the command line
tmp/outfile.txt \
| jq -r '.LogResult' | base64 -D
+create-rds-instance: ## Creates an RDS MySQL DB instance
+ aws rds create-db-instance \
+ --db-instance-identifier MyInstance01 \
+ --db-instance-class db.t1.micro \
+ --engine mysql \
+ --allocated-storage 10 \
+ --master-username master \
+ --master-user-password $(DBPASSWD)
+
+delete-rds-instance: ## Deletes an RDS MySQL DB instance
+ aws rds delete-db-instance \
+ --db-instance-identifier MyInstance01 \
+ --skip-final-snapshot
+
+db-connect: ## Connects to the RDS instance
+ mysql --user=master --password=$(DBPASSWD) --host myinstance01.cgic5q3lz0bb.us-east-1.rds.amazonaws.com
+
+create-db: ## Creates a DB with a table and records
+ @echo "Dropping and creating database"
+ @echo "-------------------------------"
+ @mysql -u master --password='$(DBPASSWD)' --host myinstance01.cgic5q3lz0bb.us-east-1.rds.amazonaws.com -e "DROP DATABASE IF EXISTS $(DBNAME)" > /dev/null 2>&1
+ @mysql -u master --password='$(DBPASSWD)' --host myinstance01.cgic5q3lz0bb.us-east-1.rds.amazonaws.com -e "CREATE DATABASE $(DBNAME)" > /dev/null 2>&1
+ @mysql -u master --password='$(DBPASSWD)' --host myinstance01.cgic5q3lz0bb.us-east-1.rds.amazonaws.com $(DBNAME) < resources/schema.sql > /dev/null 2>&1
+ @mysql -u master --password='$(DBPASSWD)' --host myinstance01.cgic5q3lz0bb.us-east-1.rds.amazonaws.com $(DBNAME) < resources/seed.sql > /dev/null 2>&1
+ @echo "... Done"
+
.PHONY: help
help:
View
@@ -0,0 +1,10 @@
+DROP TABLE IF EXISTS `users`;
+
+CREATE TABLE `users` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `login` varchar(255) DEFAULT NULL,
+ `email` varchar(255) NOT NULL DEFAULT '',
+ `firstname` varchar(255) DEFAULT NULL,
+ `lastname` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
View
@@ -0,0 +1,3 @@
+INSERT INTO `users` VALUES (1, 'jsmith', 'jsmith@gmail.com', 'John', 'Smith');
+INSERT INTO `users` VALUES (2, 'bjones', 'bjones@gmail.com', 'Bob', 'Jones');
+

0 comments on commit 435c767

Please sign in to comment.