Skip to content

Commit

Permalink
Add java11 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mhart committed Nov 18, 2019
1 parent a94337a commit 3bf429a
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ examples/go1.x/handler
examples/dotnetcore2.0/pub
examples/dotnetcore2.1/pub
base/tar-find-layer/layer.zip
base/dump-java11/build
base/dump-java11/.settings
base/dump-java11/.project
base/dump-java11/.vscode
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ These follow the Lambda runtime names:
- `python3.8`
- `ruby2.5`
- `java8`
- `java11`
- `go1.x`
- `dotnetcore2.0`
- `dotnetcore2.1`
Expand All @@ -222,6 +223,7 @@ These follow the Lambda runtime names:
- `build-python3.8`
- `build-ruby2.5`
- `build-java8`
- `build-java11`
- `build-go1.x`
- `build-dotnetcore2.0`
- `build-dotnetcore2.1`
Expand Down
2 changes: 1 addition & 1 deletion base/build-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 java8 java11 dotnetcore2.0 dotnetcore2.1"

TOP_DIR="${PWD}/.."

Expand Down
8 changes: 7 additions & 1 deletion base/diff-2.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="nodejs10.x nodejs12.x python3.8"
RUNTIMES="nodejs10.x nodejs12.x python3.8 java11"

rm -rf diff-2
mkdir -p diff-2
Expand Down Expand Up @@ -51,3 +51,9 @@ pwd
diff docker/var/runtime lambda/var/runtime
diff -qr docker lambda
echo

cd ${DIFF_DIR}/java11
pwd
diff docker/var/runtime lambda/var/runtime
diff -qr docker lambda
echo
28 changes: 28 additions & 0 deletions base/dump-java11/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'java'

sourceCompatibility = '11'
targetCompatibility = '11'

repositories {
mavenCentral()
}

dependencies {
compile (
'com.amazonaws:aws-lambda-java-core:1.2.0',
'com.amazonaws:aws-lambda-java-events:2.2.7',
'com.amazonaws:aws-java-sdk-s3:1.11.667'
)
}

task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtime
}
}

build.dependsOn buildZip

// docker run --rm -v "$PWD":/app -w /app gradle:jdk11 gradle build
66 changes: 66 additions & 0 deletions base/dump-java11/src/main/java/org/lambci/lambda/DumpJava11.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.lambci.lambda;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.Map;
import java.util.Scanner;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.PutObjectResult;

public class DumpJava11 implements RequestHandler<Object, PutObjectResult> {

@Override
public PutObjectResult handleRequest(Object input, Context context) {
String filename = "java11.tgz";
String cmd = "tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang";
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build();

System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments().toString());
System.out.println(System.getProperty("sun.java.command"));
System.out.println(System.getProperty("java.home"));
System.out.println(System.getProperty("java.library.path"));
System.out.println(System.getProperty("java.class.path"));
System.out.println(System.getProperty("user.dir"));
System.out.println(System.getProperty("user.home"));
System.out.println(System.getProperty("user.name"));
System.out.println(new File(".").getAbsolutePath());
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.println(envName + "=" + env.get(envName));
}

try {
Process process = Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd });

try (Scanner stdoutScanner = new Scanner(process.getInputStream());
Scanner stderrScanner = new Scanner(process.getErrorStream())) {
// Echo all stdout first
while (stdoutScanner.hasNextLine()) {
System.out.println(stdoutScanner.nextLine());
}
// Then echo stderr
while (stderrScanner.hasNextLine()) {
System.err.println(stderrScanner.nextLine());
}
}

process.waitFor();
if (process.exitValue() != 0) {
return null;
}

System.out.println("Zipping done! Uploading...");

return s3client.putObject(new PutObjectRequest("lambci", "fs/" + filename, new File("/tmp/" + filename))
.withCannedAcl(CannedAccessControlList.PublicRead));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
2 changes: 1 addition & 1 deletion base/publish-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 java8 java11 dotnetcore2.0 dotnetcore2.1"

echo -n "Enter repository passphrase: "
read -s DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE
Expand Down
2 changes: 1 addition & 1 deletion base/tag-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x python2.7 python3.6 python3.7 python3.8 ruby2.5 java8 java11 dotnetcore2.0 dotnetcore2.1"

git tag -f latest

Expand Down
1 change: 1 addition & 0 deletions base/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.5 lambda_function.lambda
cd ${EXAMPLES_DIR}/java
docker run --rm -v "$PWD":/app -w /app gradle gradle build
docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler '{"some": "event"}'
docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java11 org.lambci.lambda.ExampleHandler '{"some": "event"}'

cd ${EXAMPLES_DIR}/dotnetcore2.0
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.0 dotnet publish -c Release -o pub
Expand Down
3 changes: 3 additions & 0 deletions examples/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ docker run --rm -v "$PWD":/app -w /app gradle:6.0 gradle build

# Then you can run using that directory as the task directory
docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler '{"some": "event"}'

# OR
docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java11 org.lambci.lambda.ExampleHandler '{"some": "event"}'
```
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public String handleRequest(Object input, Context context) {
logger.log(context.getInvokedFunctionArn() + "\n");
logger.log(context.getLogGroupName() + "\n");
logger.log(context.getLogStreamName() + "\n");
logger.log(context.getIdentity().getIdentityId() + "\n");
logger.log(context.getIdentity().getIdentityPoolId() + "\n");
if (context.getIdentity() != null) {
logger.log(context.getIdentity().getIdentityId() + "\n");
logger.log(context.getIdentity().getIdentityPoolId() + "\n");
}
logger.log(context.getClientContext() + "\n");
logger.log(context.getMemoryLimitInMB() + "\n");
logger.log(context.getRemainingTimeInMillis() + "\n");
Expand Down
17 changes: 17 additions & 0 deletions java11/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM lambci/lambda-base-2:build

ENV PATH=/var/lang/bin:$PATH \
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
AWS_EXECUTION_ENV=AWS_Lambda_java11

RUN rm -rf /var/runtime /var/lang /var/rapid && \
curl https://lambci.s3.amazonaws.com/fs/java11.tgz | tar -zx -C / && \
mkdir /usr/local/gradle && curl -L -o gradle.zip https://services.gradle.org/distributions/gradle-5.6-bin.zip && \
unzip -d /usr/local/gradle gradle.zip && rm gradle.zip && mkdir /usr/local/maven && \
curl -L http://mirror.metrocast.net/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz | \
tar -zx -C /usr/local/maven

ENV PATH="/usr/local/gradle/gradle-5.6/bin:/usr/local/maven/apache-maven-3.6.2/bin:${PATH}"

# Add these as a separate layer as they get updated frequently
RUN pip install -U awscli boto3 aws-sam-cli==0.31.0 aws-lambda-builders==0.5.0 --no-cache-dir
22 changes: 22 additions & 0 deletions java11/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM lambci/lambda-base

RUN curl https://lambci.s3.amazonaws.com/fs/java11.tgz | tar -zx -C /opt


FROM lambci/lambda:provided


FROM lambci/lambda-base-2

ENV PATH=/var/lang/bin:$PATH \
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
AWS_EXECUTION_ENV=AWS_Lambda_java11

COPY --from=0 /opt/* /var/

COPY --from=1 /var/runtime/init /var/rapid/init

USER sbx_user1051

ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"]

0 comments on commit 3bf429a

Please sign in to comment.