Skip to content

Commit 50c7260

Browse files
Initial Java RIC Implementation (aws#190)
Co-authored-by: Bryan Moffatt <[email protected]>
1 parent fb34158 commit 50c7260

File tree

3,423 files changed

+688734
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,423 files changed

+688734
-8
lines changed

.github/workflows/maven-build-all.yml

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ jobs:
3131
run: mvn -B package --file aws-lambda-java-events-sdk-transformer/pom.xml
3232
- name: Build log4j2 with Maven
3333
run: mvn -B package --file aws-lambda-java-log4j2/pom.xml
34+
- name: Build serialization with Maven
35+
run: mvn -B package --file aws-lambda-java-serialization/pom.xml
36+
- name: Build runtime-interface-client with Maven
37+
run: mvn -B package --file aws-lambda-java-runtime-interface-client/pom.xml

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ hs_err_pid*
1313

1414
# Maven build
1515
target/
16+
dependency-reduced-pom.xml
1617

1718
# IDEA internal
1819
*.iml
1920
.idea
21+
.gradle
22+
.settings
23+
.classpath
24+
.project

README.md

+27-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Check out the per-module release notes:
1919
- [aws-lambda-java-events](aws-lambda-java-events/RELEASE.CHANGELOG.md)
2020
- [aws-lambda-java-events-sdk-transformer](aws-lambda-java-events-sdk-transformer/RELEASE.CHANGELOG.md)
2121
- [aws-lambda-java-log4j2](aws-lambda-java-log4j2/RELEASE.CHANGELOG.md)
22+
- [aws-lambda-java-runtime-interface-client](aws-lambda-java-runtime-interface-client/RELEASE.CHANGELOG.md)
23+
- [aws-lambda-java-serialization](aws-lambda-java-serialization/RELEASE.CHANGELOG.md)
2224

2325
# Where to get packages
2426
___
@@ -34,45 +36,53 @@ ___
3436
<dependency>
3537
<groupId>com.amazonaws</groupId>
3638
<artifactId>aws-lambda-java-events</artifactId>
37-
<version>3.4.0</version>
39+
<version>3.6.0</version>
3840
</dependency>
3941
<dependency>
4042
<groupId>com.amazonaws</groupId>
4143
<artifactId>aws-lambda-java-events-sdk-transformer</artifactId>
42-
<version>2.0.6</version>
44+
<version>2.0.8</version>
4345
</dependency>
4446
<dependency>
4547
<groupId>com.amazonaws</groupId>
4648
<artifactId>aws-lambda-java-log4j2</artifactId>
4749
<version>1.2.0</version>
4850
</dependency>
51+
<dependency>
52+
<groupId>com.amazonaws</groupId>
53+
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
54+
<version>1.0.0</version>
55+
</dependency>
4956
```
5057

5158
[Gradle](https://gradle.org)
5259

5360
```groovy
5461
'com.amazonaws:aws-lambda-java-core:1.2.1'
55-
'com.amazonaws:aws-lambda-java-events:3.4.0'
56-
'com.amazonaws:aws-lambda-java-events-sdk-transformer:2.0.6'
62+
'com.amazonaws:aws-lambda-java-events:3.6.0'
63+
'com.amazonaws:aws-lambda-java-events-sdk-transformer:2.0.8'
5764
'com.amazonaws:aws-lambda-java-log4j2:1.2.0'
65+
'com.amazonaws:aws-lambda-java-runtime-interface-client:1.0.0'
5866
```
5967

6068
[Leiningen](http://leiningen.org) and [Boot](http://boot-clj.com)
6169

6270
```clojure
6371
[com.amazonaws/aws-lambda-java-core "1.2.1"]
64-
[com.amazonaws/aws-lambda-java-events "3.4.0"]
65-
[com.amazonaws/aws-lambda-java-events-sdk-transformer "2.0.6"]
72+
[com.amazonaws/aws-lambda-java-events "3.6.0"]
73+
[com.amazonaws/aws-lambda-java-events-sdk-transformer "2.0.8"]
6674
[com.amazonaws/aws-lambda-java-log4j2 "1.2.0"]
75+
[com.amazonaws/aws-lambda-java-runtime-interface-client "1.0.0"]
6776
```
6877

6978
[sbt](http://www.scala-sbt.org)
7079

7180
```scala
7281
"com.amazonaws" % "aws-lambda-java-core" % "1.2.1"
73-
"com.amazonaws" % "aws-lambda-java-events" % "3.4.0"
74-
"com.amazonaws" % "aws-lambda-java-events-sdk-transformer" % "2.0.6"
82+
"com.amazonaws" % "aws-lambda-java-events" % "3.6.0"
83+
"com.amazonaws" % "aws-lambda-java-events-sdk-transformer" % "2.0.8"
7584
"com.amazonaws" % "aws-lambda-java-log4j2" % "1.2.0"
85+
"com.amazonaws" % "aws-lambda-java-runtime-interface-client" % "1.0.0"
7686
```
7787

7888
# Using aws-lambda-java-core
@@ -95,3 +105,12 @@ See the [documentation](aws-lambda-java-events-sdk-transformer/README.md) for mo
95105

96106
This package defines the Lambda adapter to use with log4j version 2.
97107
See the [README](aws-lambda-java-log4j2/README.md) or the [official documentation](http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-wt-logging-using-log4j) for information on how to use the adapter.
108+
109+
# Using aws-lambda-java-runtime-interface-client
110+
111+
This package defines the Lambda Java Runtime Interface Client package, a Lambda Runtime component that starts the runtime and interacts with the Runtime API - i.e., it calls the API for invocation events, starts the function code, calls the API to return the response.
112+
The purpose of this package is to allow developers to deploy their applications in Lambda under the form of Container Images. See the [README](aws-lambda-java-runtime-interface-client/README.md) for information on how to use the library.
113+
114+
# Using aws-lambda-java-serialization
115+
116+
This package defines the Lambda serialization logic using in the aws-lambda-java-runtime-client library. It has no current standalone usage.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
compile-flags.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.PHONY: target
2+
target:
3+
$(info ${HELP_MESSAGE})
4+
@exit 0
5+
6+
.PHONY: test
7+
test:
8+
mvn test
9+
10+
.PHONY: setup-codebuild-agent
11+
setup-codebuild-agent:
12+
docker build -t codebuild-agent - < test/integration/codebuild-local/Dockerfile.agent
13+
14+
.PHONY: test-smoke
15+
test-smoke: setup-codebuild-agent
16+
CODEBUILD_IMAGE_TAG=codebuild-agent test/integration/codebuild-local/test_one.sh test/integration/codebuild/buildspec.os.alpine.yml alpine 3.12 corretto11
17+
18+
.PHONY: test-integ
19+
test-integ: setup-codebuild-agent
20+
CODEBUILD_IMAGE_TAG=codebuild-agent test/integration/codebuild-local/test_all.sh test/integration/codebuild
21+
22+
# Command to run everytime you make changes to verify everything works
23+
.PHONY: dev
24+
dev: test
25+
26+
# Verifications to run before sending a pull request
27+
.PHONY: pr
28+
pr: test test-smoke
29+
30+
.PHONY: build
31+
build:
32+
mvn clean install
33+
34+
define HELP_MESSAGE
35+
36+
Usage: $ make [TARGETS]
37+
38+
TARGETS
39+
build Builds the package.
40+
dev Run all development tests after a change.
41+
pr Perform all checks before submitting a Pull Request.
42+
test Run the Unit tests.
43+
44+
endef
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
## AWS Lambda Java Runtime Interface Client
2+
3+
We have open-sourced a set of software packages, Runtime Interface Clients (RIC), that implement the Lambda
4+
[Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html), allowing you to seamlessly extend your preferred
5+
base images to be Lambda compatible.
6+
The Lambda Runtime Interface Client is a lightweight interface that allows your runtime to receive requests from and send requests to the Lambda service.
7+
8+
You can include this package in your preferred base image to make that base image Lambda compatible.
9+
10+
## Usage
11+
12+
### Creating a Docker Image for Lambda with the Runtime Interface Client
13+
14+
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:
15+
16+
* built for x86_64
17+
* contains Java >= 8
18+
* contains glibc >= 2.12 or musl
19+
20+
### Example
21+
22+
The Runtime Interface Client library can be installed into the image separate from the function code, but the simplest approach to keeping the Dockerfile simple is to include the library as a part of the function's dependencies!
23+
24+
Dockerfile
25+
```dockerfile
26+
# we'll use Amazon Linux 2 + Corretto 11 as our base
27+
FROM amazoncorretto:11 as base
28+
29+
# configure the build environment
30+
FROM base as build
31+
RUN yum install -y maven
32+
WORKDIR /src
33+
34+
# cache and copy dependencies
35+
ADD pom.xml .
36+
RUN mvn dependency:go-offline dependency:copy-dependencies
37+
38+
# compile the function
39+
ADD . .
40+
RUN mvn package
41+
42+
# copy the function artifact and dependencies onto a clean base
43+
FROM base
44+
WORKDIR /function
45+
46+
COPY --from=build /src/target/dependency/*.jar ./
47+
COPY --from=build /src/target/*.jar ./
48+
49+
# configure the runtime startup as main
50+
ENTRYPOINT [ "java", "-cp", "./*", "com.amazonaws.services.lambda.runtime.api.client.AWSLambda" ]
51+
# pass the name of the function handler as an argument to the runtime
52+
CMD [ "example.App::sayHello" ]
53+
```
54+
pom.xml
55+
```xml
56+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
58+
<modelVersion>4.0.0</modelVersion>
59+
<groupId>example</groupId>
60+
<artifactId>hello-lambda</artifactId>
61+
<packaging>jar</packaging>
62+
<version>1.0-SNAPSHOT</version>
63+
<name>hello-lambda</name>
64+
<url>http://maven.apache.org</url>
65+
<properties>
66+
<maven.compiler.source>1.8</maven.compiler.source>
67+
<maven.compiler.target>1.8</maven.compiler.target>
68+
</properties>
69+
<dependencies>
70+
<dependency>
71+
<groupId>com.amazonaws</groupId>
72+
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
73+
<version>1.0.0</version>
74+
</dependency>
75+
</dependencies>
76+
</project>
77+
```
78+
src/main/java/example/App.java
79+
```java
80+
package example;
81+
82+
public class App {
83+
public static String sayHello() {
84+
return "Hello λ!";
85+
}
86+
}
87+
```
88+
89+
### Local Testing
90+
91+
To make it easy to locally test Lambda functions packaged as container images we open-sourced a lightweight web-server, Lambda Runtime Interface Emulator (RIE), which allows your function packaged as a container image to accept HTTP requests. You can install the [AWS Lambda Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) on your local machine to test your function. Then when you run the image function, you set the entrypoint to be the emulator.
92+
93+
*To install the emulator and test your Lambda function*
94+
95+
1) From your project directory, run the following command to download the RIE from GitHub and install it on your local machine.
96+
97+
```shell script
98+
mkdir -p ~/.aws-lambda-rie && \
99+
curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \
100+
chmod +x ~/.aws-lambda-rie/aws-lambda-rie
101+
```
102+
2) Run your Lambda image function using the docker run command.
103+
104+
```shell script
105+
docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \
106+
--entrypoint /aws-lambda/aws-lambda-rie \
107+
myfunction:latest \
108+
java -cp ./* com.amazonaws.services.lambda.runtime.api.client.AWSLambda example.App::sayHello
109+
```
110+
111+
This runs the image as a container and starts up an endpoint locally at `http://localhost:9000/2015-03-31/functions/function/invocations`.
112+
113+
3) Post an event to the following endpoint using a curl command:
114+
115+
```shell script
116+
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'.
117+
```
118+
119+
This command invokes the function running in the container image and returns a response.
120+
121+
*Alternately, you can also include RIE as a part of your base image. See the AWS documentation on how to [Build RIE into your base image](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-alternative).*
122+
123+
124+
## Security
125+
126+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
127+
128+
## License
129+
130+
This project is licensed under the Apache-2.0 License.
131+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### December 01, 2020
2+
`1.0.0`:
3+
- Initial release of AWS Lambda Java Runtime Interface Client

0 commit comments

Comments
 (0)