-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
112 lines (98 loc) · 4.26 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
OSXDIR=hello-1.0.0-osx
LAMBDADIR=hello-1.0.0-linux-x86_64
DBPASSWD=Kew2401Sd
DBNAME=awslambdaruby
THIS_FILE := $(lastword $(MAKEFILE_LIST))
.DEFAULT_GOAL := help
run: ## Runs the code locally
@echo 'Run the app locally'
@echo '-------------------'
@rm -fr $(OSXDIR)
@mkdir -p $(OSXDIR)/lib/ruby
@tar -xzf resources/traveling-ruby-20150715-2.2.2-osx.tar.gz -C $(OSXDIR)/lib/ruby
@mkdir $(OSXDIR)/lib/app
@cp hello_ruby/lib/hello.rb $(OSXDIR)/lib/app/hello.rb
@cp -pR hello_ruby/vendor $(OSXDIR)/lib/
@rm -f $(OSXDIR)/lib/vendor/*/*/cache/*
@mkdir -p $(OSXDIR)/lib/vendor/.bundle
@cp resources/bundler-config $(OSXDIR)/lib/vendor/.bundle/config
@cp hello_ruby/Gemfile $(OSXDIR)/lib/vendor/
@cp hello_ruby/Gemfile.lock $(OSXDIR)/lib/vendor/
@cp resources/wrapper.sh $(OSXDIR)/hello
@chmod +x $(OSXDIR)/hello
@cd $(OSXDIR) && ./hello
package: ## Packages the code for AWS Lambda
@echo 'Package the app for deploy'
@echo '--------------------------'
@rm -fr $(LAMBDADIR)
@rm -fr deploy
@mkdir -p $(LAMBDADIR)/lib/ruby
@tar -xzf resources/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz -C $(LAMBDADIR)/lib/ruby
@mkdir $(LAMBDADIR)/lib/app
@cp hello_ruby/lib/hello.rb $(LAMBDADIR)/lib/app/hello.rb
@cp -pR hello_ruby/vendor $(LAMBDADIR)/lib/
@rm -fr $(LAMBDADIR)/lib/vendor/ruby/2.2.0/extensions
@tar -xzf resources/mysql2-0.3.18-linux.tar.gz -C $(LAMBDADIR)/lib/vendor/ruby/
@rm -f $(LAMBDADIR)/lib/vendor/*/*/cache/*
@mkdir -p $(LAMBDADIR)/lib/vendor/.bundle
@cp resources/bundler-config $(LAMBDADIR)/lib/vendor/.bundle/config
@cp hello_ruby/Gemfile $(LAMBDADIR)/lib/vendor/
@cp hello_ruby/Gemfile.lock $(LAMBDADIR)/lib/vendor/
@cp resources/wrapper.sh $(LAMBDADIR)/hello
@chmod +x $(LAMBDADIR)/hello
@cp resources/index.js $(LAMBDADIR)/
@cd $(LAMBDADIR) && zip -r hello_ruby.zip hello index.js lib/ > /dev/null
@mkdir deploy
@cd $(LAMBDADIR) && mv hello_ruby.zip ../deploy/
@echo '... Done.'
create: ## Creates an AWS lambda function
aws lambda create-function \
--function-name HelloFromRuby \
--handler index.handler \
--runtime nodejs4.3 \
--memory 512 \
--timeout 10 \
--description "Saying hello from MRI Ruby" \
--role arn:aws:iam::___xyz___:role/lambda_basic_execution \
--zip-file fileb://./deploy/hello_ruby.zip
publish: package ## Deploys the latest version to AWS
aws lambda update-function-code \
--function-name HelloFromRuby \
--zip-file fileb://./deploy/hello_ruby.zip
delete: ## Removes the Lambda
aws lambda delete-function --function-name HelloFromRuby
invoke: ## Invokes the AWS Lambda in the command line
rm -fr tmp && mkdir tmp
aws lambda invoke \
--invocation-type RequestResponse \
--function-name HelloFromRuby \
--log-type Tail \
--region us-east-1 \
--payload '{"name":"John Adam Smith"}' \
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:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'