| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,9 @@ | |||
| 1 | 1 | node_modules | |
| 2 | 2 | base/diff | |
| 3 | 3 | *.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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,16 +15,13 @@ same library versions that exist on AWS Lambda and then deploy using | |||
| 15 | 15 | the [AWS CLI](https://aws.amazon.com/cli/). | |
| 16 | 16 | ||
| 17 | 17 | 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). | ||
| 19 | 19 | ||
| 20 | 20 | There are also a set of build images that include packages like gcc-c++, git, | |
| 21 | 21 | zip and the aws-cli for compiling and deploying. | |
| 22 | 22 | ||
| 23 | 23 | There's also an npm module to make it convenient to invoke from Node.js | |
| 24 | 24 | ||
| 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 | - | ||
| 28 | 25 | Prerequisites | |
| 29 | 26 | ------------- | |
| 30 | 27 | ||
@@ -52,10 +49,20 @@ docker run -v "$PWD":/var/task lambci/lambda:nodejs6.10 | |||
| 52 | 49 | # Test a lambda_function.lambda_handler function from the current directory on Python2.7 | |
| 53 | 50 | docker run -v "$PWD":/var/task lambci/lambda:python2.7 | |
| 54 | 51 | ||
| 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 | + | ||
| 55 | 59 | # Run custom commands on the default container | |
| 56 | 60 | docker run --entrypoint node lambci/lambda -v | |
| 57 | 61 | ``` | |
| 58 | 62 | ||
| 63 | + You can see more examples of how to build docker images and run different | ||
| 64 | + runtimes in the [examples](./examples) directory. | ||
| 65 | + | ||
| 59 | 66 | To use the build images, for compilation, deployment, etc: | |
| 60 | 67 | ||
| 61 | 68 | ```sh | |
@@ -65,11 +72,11 @@ docker run -v "$PWD":/var/task lambci/lambda:build | |||
| 65 | 72 | # To use a different runtime from the default Node.js v4.3 | |
| 66 | 73 | docker run -v "$PWD":/var/task lambci/lambda:build-nodejs6.10 | |
| 67 | 74 | ||
| 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 | ||
| 70 | 77 | ||
| 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 | ||
| 73 | 80 | ``` | |
| 74 | 81 | ||
| 75 | 82 | Using the Node.js module (`npm install docker-lambda`) – for example in tests: | |
@@ -122,14 +129,14 @@ Questions | |||
| 122 | 129 | ||
| 123 | 130 | * *Wut, how?* | |
| 124 | 131 | ||
| 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`) | ||
| 133 | 140 | ||
| 134 | 141 | * *What's missing from the images?* | |
| 135 | 142 | ||
@@ -152,19 +159,19 @@ Questions | |||
| 152 | 159 | Documentation | |
| 153 | 160 | ------------ | |
| 154 | 161 | ||
| 155 | - TODO | ||
| 156 | - | ||
| 157 | 162 | Docker tags (follow the Lambda runtime names): | |
| 158 | 163 | - `latest` / `nodejs4.3` | |
| 159 | 164 | - `nodejs` | |
| 160 | 165 | - `nodejs6.10` | |
| 161 | 166 | - `python2.7` | |
| 162 | 167 | - `python3.6` | |
| 168 | + - `java8` | ||
| 163 | 169 | - `build` / `build-nodejs4.3` | |
| 164 | 170 | - `build-nodejs` | |
| 165 | 171 | - `build-nodejs6.10` | |
| 166 | 172 | - `build-python2.7` | |
| 167 | 173 | - `build-python3.6` | |
| 174 | + - `build-java8` | ||
| 168 | 175 | ||
| 169 | 176 | Env vars: | |
| 170 | 177 | - `AWS_LAMBDA_FUNCTION_NAME` | |
| Original file line number | Diff line number | Diff 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> | ||
| Original file line number | Diff line number | Diff 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> | ||
| Original file line number | Diff line number | Diff 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 | ||
| Original file line number | Diff line number | Diff 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> | ||
| Original file line number | Diff line number | Diff 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 | + } | ||
| Original file line number | Diff line number | Diff 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> | ||
| Original file line number | Diff line number | Diff 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> | ||
| Original file line number | Diff line number | Diff 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments