Permalink
Browse files

Package the Ruby code for AWS Lambda

  • Loading branch information...
1 parent 1ff6a6b commit 6721e9e8f7d15649385bdb9adf6593214ad6e250 @adomokos committed May 24, 2016
Showing with 34 additions and 1 deletion.
  1. +3 −1 .gitignore
  2. +18 −0 Makefile
  3. +13 −0 resources/index.js
View
@@ -1 +1,3 @@
-hello-1.0.0-osx
+hello-1.0.0-osx/
+hello-1.0.0-linux-x86_64/
+deploy/
View
@@ -1,9 +1,27 @@
OSXDIR=hello-1.0.0-osx
+LAMBDADIR=hello-1.0.0-linux-x86_64
THIS_FILE := $(lastword $(MAKEFILE_LIST))
.DEFAULT_GOAL := help
+package: ## Package 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 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/
+ mkdir deploy
+ cd $(LAMBDADIR) && mv hello_ruby.zip ../deploy/
+ @echo '... Done.'
+
run: ## Runs the code locally
@echo 'Run the app locally'
@echo '-------------------'
View
@@ -0,0 +1,13 @@
+process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']
+
+var exec = require('child_process').exec;
+exports.handler = function(event, context) {
+ var command = `./hello`;
+ child = exec(command, {env: {'LD_LIBRARY_PATH': __dirname + '/lib'}}, function(error) {
+ // Resolve with result of process
+ context.done(error, 'Process complete!');
+ });
+ // Log process stdout and stderr
+ child.stdout.on('data', console.log);
+ child.stderr.on('data', console.error);
+};

0 comments on commit 6721e9e

Please sign in to comment.