Skip to content

Commit f38ab09

Browse files
committed
add support for ARM based platforms
1 parent 4fe08f4 commit f38ab09

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

aws-lambda-java-runtime-interface-client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You can include this package in your preferred base image to make that base imag
1313

1414
Choose a preferred base image. The Runtime Interface Client is tested on Amazon Linux, Alpine, Ubuntu, Debian, and CentOS. The requirements are that the image is:
1515

16-
* built for x86_64
16+
* built for x86_64 and ARM
1717
* contains Java >= 8
1818
* contains glibc >= 2.17 or musl
1919

@@ -70,7 +70,7 @@ pom.xml
7070
<dependency>
7171
<groupId>com.amazonaws</groupId>
7272
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
73-
<version>2.0.0</version>
73+
<version>2.1.0</version>
7474
</dependency>
7575
</dependencies>
7676
<build>

aws-lambda-java-runtime-interface-client/RELEASE.CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Dec 30, 2021
2+
`2.1.0`
3+
- Added support for ARM64 architecture
4+
15
### Sept 29, 2021
26
`2.0.0`
37
- Added support for ARM64 architecture
@@ -9,4 +13,4 @@
913

1014
### December 01, 2020
1115
`1.0.0`:
12-
- Initial release of AWS Lambda Java Runtime Interface Client
16+
- Initial release of AWS Lambda Java Runtime Interface Client

aws-lambda-java-runtime-interface-client/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.amazonaws</groupId>
66
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
7-
<version>2.0.0</version>
7+
<version>2.1.0</version>
88
<packaging>jar</packaging>
99

1010
<name>AWS Lambda Java Runtime Interface Client</name>
@@ -31,6 +31,8 @@
3131
</developers>
3232

3333
<properties>
34+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3436
<maven.compiler.source>1.8</maven.compiler.source>
3537
<maven.compiler.target>1.8</maven.compiler.target>
3638
</properties>

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/runtimeapi/NativeClient.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
*/
1414
class NativeClient {
1515
private static final String nativeLibPath = "/tmp/.aws-lambda-runtime-interface-client";
16+
private static final String architecturePathSuffix = "/" + getArchIdentifier();
1617
private static final String[] libsToTry = {
17-
"/aws-lambda-runtime-interface-client.glibc.so",
18-
"/aws-lambda-runtime-interface-client.musl.so",
18+
"aws-lambda-runtime-interface-client.glibc.so",
19+
"aws-lambda-runtime-interface-client.musl.so",
1920
};
2021
private static final Throwable[] exceptions = new Throwable[libsToTry.length];
2122
static {
2223
boolean loaded = false;
2324
for (int i = 0; !loaded && i < libsToTry.length; ++i) {
24-
try (InputStream lib = NativeClient.class.getResourceAsStream(libsToTry[i])) {
25+
try (InputStream lib = NativeClient.class.getResourceAsStream(
26+
Paths.get(architecturePathSuffix, libsToTry[i]).toString())) {
2527
Files.copy(lib, Paths.get(nativeLibPath), StandardCopyOption.REPLACE_EXISTING);
2628
System.load(nativeLibPath);
2729
loaded = true;
@@ -44,10 +46,25 @@ class NativeClient {
4446
initializeClient(userAgent.getBytes());
4547
}
4648

49+
/**
50+
* @return a string describing the detected architecture the RIC is executing on
51+
* @throws RuntimeException
52+
*/
53+
static String getArchIdentifier() {
54+
String arch = System.getProperty("os.arch");
55+
56+
if (arch.matches("^(x8664|amd64|ia32e|em64t|x64|x86_64|x8632|x86|i[3-6]86|ia32|x32)$")) {
57+
return "x86";
58+
} else if (arch.matches("^(armeabi.*|arm64.*|aarch64.*|arm)$")) {
59+
return "arm";
60+
}
61+
62+
throw new RuntimeException("architecture not supported: " + arch);
63+
}
64+
4765
static native void initializeClient(byte[] userAgent);
4866

4967
static native InvocationRequest next();
5068

5169
static native void postInvocationResponse(byte[] requestId, byte[] response);
52-
5370
}

aws-lambda-java-runtime-interface-client/src/main/jni/build-jni-lib.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ SRC_DIR=$(dirname "$0")
77
DST_DIR=${1}
88
CURL_VERSION=7.77.0
99

10-
# compile the native library
11-
docker build -f "${SRC_DIR}/Dockerfile.glibc" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-glibc "${SRC_DIR}"
12-
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-glibc /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/aws-lambda-runtime-interface-client.glibc.so
10+
# compile the native library for x86
11+
mkdir "${DST_DIR}"/classes/x86
12+
docker build --platform=linux/amd64 -f "${SRC_DIR}/Dockerfile.glibc" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-glibc-x86 "${SRC_DIR}"
13+
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-glibc-x86 /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/x86/aws-lambda-runtime-interface-client.glibc.so
1314

14-
docker build -f "${SRC_DIR}/Dockerfile.musl" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-musl "${SRC_DIR}"
15-
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-musl /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/aws-lambda-runtime-interface-client.musl.so
15+
docker build --platform=linux/amd64 -f "${SRC_DIR}/Dockerfile.musl" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-musl-x86 "${SRC_DIR}"
16+
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-musl-x86 /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/x86/aws-lambda-runtime-interface-client.musl.so
1617

18+
# compile the native library for ARM
19+
mkdir "${DST_DIR}"/classes/arm
20+
docker build --platform=linux/arm64/v8 -f "${SRC_DIR}/Dockerfile.glibc" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-glibc-arm "${SRC_DIR}"
21+
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-glibc-arm /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/arm/aws-lambda-runtime-interface-client.glibc.so
22+
23+
docker build --platform=linux/arm64/v8 -f "${SRC_DIR}/Dockerfile.musl" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-musl-arm "${SRC_DIR}"
24+
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-musl-arm /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/arm/aws-lambda-runtime-interface-client.musl.so

0 commit comments

Comments
 (0)