Skip to content

Commit 6dacf38

Browse files
committed
improve documentation, remove Dockerfile comment
1 parent bf52ad4 commit 6dacf38

File tree

2 files changed

+119
-8
lines changed

2 files changed

+119
-8
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
# https://rieckpil.de/java-aws-lambda-container-image-support-complete-guide/
19-
2018
ARG JAVA_VERSION=17
2119
ARG JAVA_REVISION=17.0.3
2220

cfn-build.yml

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,128 @@ Resources:
2121
LambdaJavaBaseImageRepository:
2222
Type: AWS::ECR::PublicRepository
2323
Properties:
24-
RepositoryName: sigpwned/aws-lambda-java-base-image
24+
RepositoryName: lambda/java
2525
RepositoryCatalogData:
26-
AboutText: "AWS Lambda Base Images for Java 17+"
27-
UsageText: "AWS Lambda Base Images for Java 17+"
28-
RepositoryDescription: "AWS Lambda Base Images for Java 17+"
26+
AboutText: |+
27+
Unofficial base image for Lambda that contains all the required components to run your
28+
functions packaged as container images on AWS Lambda. This base image contains the Amazon
29+
Linux Base operating system, the runtime for Java, dependencies and the Lambda Runtime
30+
Interface Client (RIC), which implements the
31+
[Lambda Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html).
32+
The Lambda Runtime Interface Client allows your runtime to receive requests from and send
33+
requests to the Lambda service.
34+
35+
To learn more about the composition of this base image you can visit
36+
[https://github.com/aleph0io/aws-lambda-java-base-images](https://github.com/aleph0io/aws-lambda-java-base-images).
37+
38+
## Maintenance policy
39+
40+
These images will be updated periodically to pick up new security patches. The components
41+
and dependencies included in the image may change from time to time, but they will always
42+
work for deploying images to AWS Lambda.
43+
UsageText: |-
44+
You can find an entire example AWS Lambda function implementation at
45+
[https://github.com/sigpwned/example-java-17-lambda-function](https://github.com/sigpwned/example-java-17-lambda-function).
46+
47+
Otherwise, you can get started by using these images in your Dockerfile and coping your
48+
class files into the `/var/task` folder in your image. The runtime jar dependencies should
49+
be copied into `/var/task/lib` directory.
50+
51+
```
52+
FROM public.ecr.aws/aleph0io/lambda/java:17
53+
54+
# Copy function code and runtime dependencies from Gradle layout
55+
COPY build/classes/java/main ${LAMBDA_TASK_ROOT}
56+
COPY build/dependency/* ${LAMBDA_TASK_ROOT}/lib/
57+
58+
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
59+
CMD [ "com.example.LambdaHandler::handleRequest" ]
60+
```
61+
62+
Example Gradle task definition to prepare the runtime dependencies:
63+
64+
```
65+
task copyRuntimeDependencies(type: Copy) {
66+
from configurations.runtimeClasspath
67+
into 'build/dependency'
68+
}
69+
70+
build.dependsOn copyRuntimeDependencies
71+
```
72+
73+
If you are using Maven, adjust COPY command in the Dockerfile accordingly:
74+
75+
```
76+
FROM public.ecr.aws/aleph0io/lambda/java:17
77+
78+
# Copy function code and runtime dependencies from Maven layout
79+
COPY target/classes ${LAMBDA_TASK_ROOT}
80+
COPY target/dependency/* ${LAMBDA_TASK_ROOT}/lib/
81+
82+
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
83+
CMD [ "com.example.LambdaHandler::handleRequest" ]
84+
```
85+
86+
You can use maven-dependency-plugin to collect runtime dependencies:
87+
88+
```
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-dependency-plugin</artifactId>
94+
<version>3.1.2</version>
95+
<executions>
96+
<execution>
97+
<id>copy-dependencies</id>
98+
<phase>package</phase>
99+
<goals>
100+
<goal>copy-dependencies</goal>
101+
</goals>
102+
<configuration>
103+
<!-- Configuration goes here -->
104+
</configuration>
105+
</execution>
106+
</executions>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
```
111+
112+
Use `mvn compile dependency:copy-dependencies -DincludeScope=runtime` to compile the
113+
project and collect the runtime dependencies.
114+
115+
The resulting layout should look like:
116+
117+
/var/task/
118+
├── com
119+
│ └── example
120+
│ ├── LambdaHandler.class
121+
│ └── <your other class files here>
122+
└── lib
123+
├── aws-lambda-java-core-1.2.1.jar
124+
├── aws-lambda-java-events-3.7.0.jar
125+
└── <your other JAR dependencies here>
126+
127+
You can then locally test your function using the docker build and docker run commands.
128+
129+
To build your image:
130+
131+
docker build -t <image name> .
132+
133+
To run your image locally:
134+
135+
docker run -p 9000:8080 <image name>
136+
137+
In a separate terminal, you can then locally invoke the function using cURL:
138+
139+
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
140+
RepositoryDescription: >
141+
AWS Lambda Base Images for Java 17+
29142
OperatingSystems:
30-
- al2
143+
- Linux
31144
Architectures:
32-
- x86_64
145+
- x86-64
33146
Tags:
34147
- Key: aleph0
35148
Value: true

0 commit comments

Comments
 (0)