Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 814e04e

Browse filesBrowse files
authored
First cut of java8 implementation (lambci#48)
* Fixes lambci#1
1 parent 159788e commit 814e04e
Copy full SHA for 814e04e

File tree

Expand file treeCollapse file tree

23 files changed

+800
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

23 files changed

+800
-18
lines changed
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
node_modules
22
base/diff
33
*.pyc
4+
.gradle
5+
java8/run/lambda-runtime-mock/target
6+
base/dump-java8/target
7+
examples/java/build
8+
examples/java/target
9+
examples/java/bin
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+25-18Lines changed: 25 additions & 18 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ same library versions that exist on AWS Lambda and then deploy using
1515
the [AWS CLI](https://aws.amazon.com/cli/).
1616

1717
This project consists of a set of Docker images for each of the supported Lambda runtimes
18-
(Node.js 0.10, 4.3 and 6.10, Python 2.7 and 3.6, and Java 8\*).
18+
(Node.js 0.10, 4.3 and 6.10, Python 2.7 and 3.6, and Java 8).
1919

2020
There are also a set of build images that include packages like gcc-c++, git,
2121
zip and the aws-cli for compiling and deploying.
2222

2323
There's also an npm module to make it convenient to invoke from Node.js
2424

25-
\* NB: The Java 8 test runner is not yet complete, but the
26-
language is installed in the images so can be manually tested
27-
2825
Prerequisites
2926
-------------
3027

@@ -52,10 +49,20 @@ docker run -v "$PWD":/var/task lambci/lambda:nodejs6.10
5249
# Test a lambda_function.lambda_handler function from the current directory on Python2.7
5350
docker run -v "$PWD":/var/task lambci/lambda:python2.7
5451

52+
# Test a function from the current directory on Java 8
53+
# The directory must be laid out in the same way the Lambda zip file is,
54+
# with top-level package source directories and a `lib` directory for third-party jars
55+
# http://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html
56+
# The default handler is "index.Handler", but you'll likely have your own package and class
57+
docker run -v "$PWD":/var/task lambci/lambda:java8 org.myorg.MyHandler
58+
5559
# Run custom commands on the default container
5660
docker run --entrypoint node lambci/lambda -v
5761
```
5862

63+
You can see more examples of how to build docker images and run different
64+
runtimes in the [examples](./examples) directory.
65+
5966
To use the build images, for compilation, deployment, etc:
6067

6168
```sh
@@ -65,11 +72,11 @@ docker run -v "$PWD":/var/task lambci/lambda:build
6572
# To use a different runtime from the default Node.js v4.3
6673
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs6.10
6774

68-
# Run custom commands on the build container
69-
docker run lambci/lambda:build java -version
75+
# Run custom commands on a build container
76+
docker run lambci/lambda:build aws --version
7077

71-
# To run an interactive session on the build container
72-
docker run -it lambci/lambda:build bash
78+
# To run an interactive session on a build container
79+
docker run -it lambci/lambda:build-python3.6 bash
7380
```
7481

7582
Using the Node.js module (`npm install docker-lambda`) – for example in tests:
@@ -122,14 +129,14 @@ Questions
122129

123130
* *Wut, how?*
124131

125-
By tarring the full filesystem in Lambda, uploading that to S3, and then
126-
piping into Docker to create a new image from scratch – then creating
127-
mock modules that will be required/included in place of the actual native
128-
modules that communicate with the real Lambda coordinating services. Only the
129-
native modules are mocked out – the actual parent JS/PY runner files are left
130-
alone, so their behaviors don't need to be replicated (like the
131-
overriding of `console.log`, and custom defined properties like
132-
`callbackWaitsForEmptyEventLoop`)
132+
By [tarring the full filesystem in Lambda, uploading that to S3](./base/dump-nodejs43.js),
133+
and then [piping into Docker to create a new image from scratch](./base/create-base.sh)
134+
then [creating mock modules](./nodejs4.3/run/awslambda-mock.js) that will be
135+
required/included in place of the actual native modules that communicate with
136+
the real Lambda coordinating services. Only the native modules are mocked
137+
out – the actual parent JS/PY/Java runner files are left alone, so their behaviors
138+
don't need to be replicated (like the overriding of `console.log`, and custom
139+
defined properties like `callbackWaitsForEmptyEventLoop`)
133140

134141
* *What's missing from the images?*
135142

@@ -152,19 +159,19 @@ Questions
152159
Documentation
153160
------------
154161

155-
TODO
156-
157162
Docker tags (follow the Lambda runtime names):
158163
- `latest` / `nodejs4.3`
159164
- `nodejs`
160165
- `nodejs6.10`
161166
- `python2.7`
162167
- `python3.6`
168+
- `java8`
163169
- `build` / `build-nodejs4.3`
164170
- `build-nodejs`
165171
- `build-nodejs6.10`
166172
- `build-python2.7`
167173
- `build-python3.6`
174+
- `build-java8`
168175

169176
Env vars:
170177
- `AWS_LAMBDA_FUNCTION_NAME`
Collapse file

‎base/dump-java8/.classpath‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
15+
<attributes>
16+
<attribute name="maven.pomderived" value="true"/>
17+
</attributes>
18+
</classpathentry>
19+
<classpathentry kind="output" path="target/classes"/>
20+
</classpath>
Collapse file

‎base/dump-java8/.project‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>dump-java8</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.8
Collapse file

‎base/dump-java8/pom.xml‎

Copy file name to clipboard
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.lambci.lambda</groupId>
6+
<artifactId>dump-java8</artifactId>
7+
<version>1.0.0</version>
8+
<packaging>jar</packaging>
9+
10+
<build>
11+
<plugins>
12+
<plugin>
13+
<groupId>org.apache.maven.plugins</groupId>
14+
<artifactId>maven-compiler-plugin</artifactId>
15+
<version>3.6.0</version>
16+
<configuration>
17+
<source>1.8</source>
18+
<target>1.8</target>
19+
<encoding>UTF-8</encoding>
20+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
21+
</configuration>
22+
</plugin>
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-shade-plugin</artifactId>
26+
<version>3.0.0</version>
27+
<executions>
28+
<execution>
29+
<phase>package</phase>
30+
<goals>
31+
<goal>shade</goal>
32+
</goals>
33+
<configuration>
34+
<artifactSet>
35+
<excludes>
36+
<exclude>com.amazonaws:aws-lambda-java-events</exclude>
37+
<exclude>com.amazonaws:aws-lambda-java-core</exclude>
38+
</excludes>
39+
</artifactSet>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<dependencyManagement>
48+
<dependencies>
49+
<dependency>
50+
<groupId>com.amazonaws</groupId>
51+
<artifactId>aws-java-sdk-bom</artifactId>
52+
<version>1.11.124</version>
53+
<type>pom</type>
54+
<scope>import</scope>
55+
</dependency>
56+
</dependencies>
57+
</dependencyManagement>
58+
59+
<dependencies>
60+
<dependency>
61+
<groupId>com.amazonaws</groupId>
62+
<artifactId>aws-lambda-java-events</artifactId>
63+
<version>1.3.0</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.amazonaws</groupId>
67+
<artifactId>aws-lambda-java-core</artifactId>
68+
<version>1.1.0</version>
69+
</dependency>
70+
</dependencies>
71+
</project>
Collapse file
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.lambci.lambda;
2+
3+
import java.io.File;
4+
import java.lang.management.ManagementFactory;
5+
import java.util.Map;
6+
import java.util.Scanner;
7+
8+
import com.amazonaws.services.lambda.runtime.Context;
9+
import com.amazonaws.services.lambda.runtime.RequestHandler;
10+
import com.amazonaws.services.s3.AmazonS3;
11+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
12+
import com.amazonaws.services.s3.model.CannedAccessControlList;
13+
import com.amazonaws.services.s3.model.PutObjectRequest;
14+
import com.amazonaws.services.s3.model.PutObjectResult;
15+
16+
public class DumpJava8 implements RequestHandler<Object, PutObjectResult> {
17+
18+
@Override
19+
public PutObjectResult handleRequest(Object input, Context context) {
20+
String filename = "java8.tgz";
21+
String cmd = "tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang";
22+
// String filename = "java8.fs.txt";
23+
// String cmd = "find / -ls | grep -v /proc | grep -v /var/runtime | grep -v /var/task | grep -v /var/lang | sort -k11 > /tmp/" + filename;
24+
AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
25+
26+
System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments().toString());
27+
System.out.println(System.getProperty("sun.java.command"));
28+
System.out.println(System.getProperty("java.home"));
29+
System.out.println(System.getProperty("java.library.path"));
30+
System.out.println(System.getProperty("user.dir"));
31+
System.out.println(System.getProperty("user.home"));
32+
System.out.println(System.getProperty("user.name"));
33+
System.out.println(new File(".").getAbsolutePath());
34+
Map<String, String> env = System.getenv();
35+
for (String envName : env.keySet()) {
36+
System.out.println(envName + "=" + env.get(envName));
37+
}
38+
39+
try {
40+
Process process = Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd });
41+
42+
try (Scanner stdoutScanner = new Scanner(process.getInputStream());
43+
Scanner stderrScanner = new Scanner(process.getErrorStream())) {
44+
// Echo all stdout first
45+
while (stdoutScanner.hasNextLine()) {
46+
System.out.println(stdoutScanner.nextLine());
47+
}
48+
// Then echo stderr
49+
while (stderrScanner.hasNextLine()) {
50+
System.err.println(stderrScanner.nextLine());
51+
}
52+
}
53+
54+
process.waitFor();
55+
if (process.exitValue() != 0) {
56+
return null;
57+
}
58+
59+
System.out.println("Zipping done! Uploading...");
60+
61+
return s3client.putObject(new PutObjectRequest("lambci", "fs/" + filename, new File("/tmp/" + filename))
62+
.withCannedAcl(CannedAccessControlList.PublicRead));
63+
} catch (Exception e) {
64+
throw new RuntimeException(e);
65+
}
66+
}
67+
}
Collapse file

‎examples/java/.classpath‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
15+
<attributes>
16+
<attribute name="maven.pomderived" value="true"/>
17+
</attributes>
18+
</classpathentry>
19+
<classpathentry kind="output" path="target/classes"/>
20+
</classpath>
Collapse file

‎examples/java/.project‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>example-handler</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.8

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.