Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
59 changes: 0 additions & 59 deletions LICENSE.RUBY

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Run ruby code on JRuby on AWS Lambda Java
4. Upload zip file
Zip file is created into build/distributions

5. Run Lambda function
5. Run Lambda function

needs timeout of at least 60 sec for the first execution of the lambda
47 changes: 39 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,56 @@ apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

buildscript {
repositories { jcenter() }

dependencies {
classpath "com.github.jruby-gradle:jruby-gradle-jar-plugin:1.2.0"
}
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8

apply plugin: 'com.github.jruby-gradle.jar'

jrubyJar {
initScript library()
from ('src/main/ruby') {
include '*.rb'
}
}

dependencies {
gems 'rubygems:aws-sdk:2.2.31'

compile (
'com.amazonaws:aws-lambda-java-core:1.0.0',
'com.amazonaws:aws-lambda-java-events:1.0.0',
'com.google.code.gson:gson:2.3.1',
'com.amazonaws:aws-lambda-java-core:1.1.0',
//'com.amazonaws:aws-lambda-java-events:1.1.0',
'org.jruby:jruby:9.0.5.0',
)
compile files('lib/jruby.jar')


}

configurations {
jrubyJar.extendsFrom gems
}


task buildZip(type: Zip) {
dependsOn jrubyJar
from compileJava
from processResources
from processResources
into('lib') {
from configurations.runtime
}
from('build/libs') {
include '*jruby-jruby.jar'
}
from configurations.runtime
}
}

build.dependsOn buildZip
build.dependsOn buildZip
Binary file removed lib/jruby.jar
Binary file not shown.
41 changes: 16 additions & 25 deletions src/main/java/AWSLambdaJRuby.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;

import org.jruby.Ruby;
import org.jruby.embed.IsolatedScriptingContainer;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;

import com.amazonaws.services.lambda.runtime.Context;
import com.google.gson.Gson;

public class AWSLambdaJRuby {

private static final String mainRubyFile = "main.rb";
private static final String gemsRubyFile = "gems.rb";

private static final String rubyFileName = "main.rb";

static {
Ruby.newInstance();
}

@SuppressWarnings("rawtypes")
public String handler(Map data, Context context) throws Exception {

ScriptingContainer container = new ScriptingContainer();
String arg = new Gson().toJson(data);
context.getLogger().log(arg);

//add std lib path
URL stdLibPath = getClass().getResource("/stdlib/").toURI().toURL();
container.addLoadPath(new URLClassLoader(new URL[]{stdLibPath}));

//set argument of lambda function to ruby global variable as JSON format
container.put("$lambda_arg", arg);
// uploaded zip is extracted to /var/task directory
container.setCurrentDirectory("/var/task");
Object result = container.runScriptlet(PathType.CLASSPATH,rubyFileName);
IsolatedScriptingContainer container = new IsolatedScriptingContainer();

context.getLogger().log(data.toString());

container.put("$lambda_arg", data);

String result = "";
result += "yaml: " + container.runScriptlet(PathType.CLASSPATH, mainRubyFile);
result += " gems: " + container.runScriptlet(PathType.CLASSPATH, gemsRubyFile);


return result == null ? null : result.toString();
return result;
}

}
}
4 changes: 0 additions & 4 deletions src/main/resources/main.rb

This file was deleted.

Empty file.
189 changes: 0 additions & 189 deletions src/main/resources/stdlib/English.rb

This file was deleted.

Loading