├── .github
├── dependabot.yml
└── workflows
│ ├── deliver17.yml
│ ├── deliver18.yml
│ ├── deliver19.yml
│ ├── deliver20.yml
│ ├── deliver21.yml
│ ├── integration.yml
│ └── stale.yml
├── .gitignore
├── Dockerfile
├── LICENSE.md
├── README.md
├── cfn-build.yml
└── pom.xml
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "docker"
4 | directory: "/"
5 | target-branch: main
6 | schedule:
7 | interval: "daily"
8 | - package-ecosystem: "maven"
9 | directory: "/"
10 | target-branch: main
11 | schedule:
12 | interval: "daily"
13 | - package-ecosystem: "github-actions"
14 | directory: "/"
15 | target-branch: main
16 | schedule:
17 | interval: "daily"
18 |
--------------------------------------------------------------------------------
/.github/workflows/deliver17.yml:
--------------------------------------------------------------------------------
1 | name: deliver17
2 |
3 | on:
4 | push:
5 | branches:
6 | - release/17
7 |
8 | permissions:
9 | id-token: write
10 | contents: read
11 |
12 | jobs:
13 | deploy:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout source code
17 | uses: actions/checkout@v4
18 | - name: Set up JDK 17
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '17'
22 | distribution: 'corretto'
23 | - name: Cache local Maven repository
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.m2/repository
27 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28 | restore-keys: |
29 | ${{ runner.os }}-maven-
30 | - name: Configure AWS credentials
31 | uses: aws-actions/configure-aws-credentials@v4
32 | with:
33 | role-to-assume: arn:aws:iam::${{ secrets.CD_AWS_ACCOUNT_ID }}:role/GitHubRole
34 | aws-region: us-east-1
35 | - name: Login to Amazon ECR Public
36 | uses: aws-actions/amazon-ecr-login@v2
37 | with:
38 | registry-type: "public"
39 | - name: Deploy artifacts
40 | run: mvn -B clean dependency:copy-dependencies docker:build docker:tag docker:push
--------------------------------------------------------------------------------
/.github/workflows/deliver18.yml:
--------------------------------------------------------------------------------
1 | name: deliver18
2 |
3 | on:
4 | push:
5 | branches:
6 | - release/18
7 |
8 | permissions:
9 | id-token: write
10 | contents: read
11 |
12 | jobs:
13 | deploy:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout source code
17 | uses: actions/checkout@v4
18 | - name: Set up JDK 18
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '18'
22 | distribution: 'corretto'
23 | - name: Cache local Maven repository
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.m2/repository
27 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28 | restore-keys: |
29 | ${{ runner.os }}-maven-
30 | - name: Configure AWS credentials
31 | uses: aws-actions/configure-aws-credentials@v4
32 | with:
33 | role-to-assume: arn:aws:iam::${{ secrets.CD_AWS_ACCOUNT_ID }}:role/GitHubRole
34 | aws-region: us-east-1
35 | - name: Login to Amazon ECR Public
36 | uses: aws-actions/amazon-ecr-login@v2
37 | with:
38 | registry-type: "public"
39 | - name: Deploy artifacts
40 | run: mvn -B clean dependency:copy-dependencies docker:build docker:tag docker:push
--------------------------------------------------------------------------------
/.github/workflows/deliver19.yml:
--------------------------------------------------------------------------------
1 | name: deliver19
2 |
3 | on:
4 | push:
5 | branches:
6 | - release/19
7 |
8 | permissions:
9 | id-token: write
10 | contents: read
11 |
12 | jobs:
13 | deploy:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout source code
17 | uses: actions/checkout@v4
18 | - name: Set up JDK 19
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '19'
22 | distribution: 'corretto'
23 | - name: Cache local Maven repository
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.m2/repository
27 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28 | restore-keys: |
29 | ${{ runner.os }}-maven-
30 | - name: Configure AWS credentials
31 | uses: aws-actions/configure-aws-credentials@v4
32 | with:
33 | role-to-assume: arn:aws:iam::${{ secrets.CD_AWS_ACCOUNT_ID }}:role/GitHubRole
34 | aws-region: us-east-1
35 | - name: Login to Amazon ECR Public
36 | uses: aws-actions/amazon-ecr-login@v2
37 | with:
38 | registry-type: "public"
39 | - name: Deploy artifacts
40 | run: mvn -B clean dependency:copy-dependencies docker:build docker:tag docker:push
--------------------------------------------------------------------------------
/.github/workflows/deliver20.yml:
--------------------------------------------------------------------------------
1 | name: deliver20
2 |
3 | on:
4 | push:
5 | branches:
6 | - release/20
7 |
8 | permissions:
9 | id-token: write
10 | contents: read
11 |
12 | jobs:
13 | deploy:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout source code
17 | uses: actions/checkout@v4
18 | - name: Set up JDK 20
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '20'
22 | distribution: 'corretto'
23 | - name: Cache local Maven repository
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.m2/repository
27 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28 | restore-keys: |
29 | ${{ runner.os }}-maven-
30 | - name: Configure AWS credentials
31 | uses: aws-actions/configure-aws-credentials@v4
32 | with:
33 | role-to-assume: arn:aws:iam::${{ secrets.CD_AWS_ACCOUNT_ID }}:role/GitHubRole
34 | aws-region: us-east-1
35 | - name: Login to Amazon ECR Public
36 | uses: aws-actions/amazon-ecr-login@v2
37 | with:
38 | registry-type: "public"
39 | - name: Deploy artifacts
40 | run: mvn -B clean dependency:copy-dependencies docker:build docker:tag docker:push
--------------------------------------------------------------------------------
/.github/workflows/deliver21.yml:
--------------------------------------------------------------------------------
1 | name: deliver21
2 |
3 | on:
4 | push:
5 | branches:
6 | - release/21
7 |
8 | permissions:
9 | id-token: write
10 | contents: read
11 |
12 | jobs:
13 | deploy:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout source code
17 | uses: actions/checkout@v4
18 | - name: Set up JDK 21
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '21'
22 | distribution: 'corretto'
23 | - name: Cache local Maven repository
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.m2/repository
27 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28 | restore-keys: |
29 | ${{ runner.os }}-maven-
30 | - name: Configure AWS credentials
31 | uses: aws-actions/configure-aws-credentials@v4
32 | with:
33 | role-to-assume: arn:aws:iam::${{ secrets.CD_AWS_ACCOUNT_ID }}:role/GitHubRole
34 | aws-region: us-east-1
35 | - name: Login to Amazon ECR Public
36 | uses: aws-actions/amazon-ecr-login@v2
37 | with:
38 | registry-type: "public"
39 | - name: Deploy artifacts
40 | run: mvn -B clean dependency:copy-dependencies docker:build docker:tag docker:push
41 |
--------------------------------------------------------------------------------
/.github/workflows/integration.yml:
--------------------------------------------------------------------------------
1 | name: integration
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | permissions:
9 | id-token: write
10 | contents: read
11 |
12 | jobs:
13 | deploy:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout source code
17 | uses: actions/checkout@v4
18 | - name: Set up JDK 17
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '17'
22 | distribution: 'corretto'
23 | - name: Cache local Maven repository
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.m2/repository
27 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28 | restore-keys: |
29 | ${{ runner.os }}-maven-
30 | - name: Configure AWS credentials
31 | uses: aws-actions/configure-aws-credentials@v4
32 | with:
33 | role-to-assume: arn:aws:iam::${{ secrets.CD_AWS_ACCOUNT_ID }}:role/GitHubRole
34 | aws-region: us-east-1
35 | - name: Login to Amazon ECR Public
36 | uses: aws-actions/amazon-ecr-login@v2
37 | with:
38 | registry-type: "public"
39 | - name: Build and test
40 | run: mvn -B clean dependency:copy-dependencies docker:build
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
2 | #
3 | # You can adjust the behavior by modifying this file.
4 | # For more information, see:
5 | # https://github.com/actions/stale
6 | name: Mark stale issues and pull requests
7 |
8 | on:
9 | schedule:
10 | - cron: '20 14 * * *'
11 |
12 | jobs:
13 | stale:
14 |
15 | runs-on: ubuntu-latest
16 | permissions:
17 | issues: write
18 | pull-requests: write
19 |
20 | steps:
21 | - uses: actions/stale@v8
22 | with:
23 | repo-token: ${{ secrets.GITHUB_TOKEN }}
24 | stale-issue-message: 'Stale issue message'
25 | stale-pr-message: 'Stale pull request message'
26 | stale-issue-label: 'no-issue-activity'
27 | stale-pr-label: 'no-pr-activity'
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # From https://github.com/github/gitignore/blob/main/Java.gitignore
2 |
3 | # Keys
4 | *.p12
5 |
6 | # Compiled class file
7 | *.class
8 |
9 | # Log file
10 | *.log
11 |
12 | # BlueJ files
13 | *.ctxt
14 |
15 | # Mobile Tools for Java (J2ME)
16 | .mtj.tmp/
17 |
18 | # Package Files #
19 | *.jar
20 | *.war
21 | *.nar
22 | *.ear
23 | *.zip
24 | *.tar.gz
25 | *.rar
26 |
27 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28 | hs_err_pid*
29 | replay_pid*
30 |
31 | # From https://github.com/github/gitignore/blob/main/Maven.gitignore
32 |
33 | target/
34 | pom.xml.tag
35 | pom.xml.releaseBackup
36 | pom.xml.versionsBackup
37 | pom.xml.next
38 | release.properties
39 | dependency-reduced-pom.xml
40 | buildNumber.properties
41 | .mvn/timing.properties
42 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar
43 | .mvn/wrapper/maven-wrapper.jar
44 |
45 | # Eclipse m2e generated files
46 | # Eclipse Core
47 | .project
48 | # JDT-specific (Eclipse Java Development Tools)
49 | .classpath
50 |
51 | # Other
52 |
53 | # Emacs temporary files
54 | *~
55 |
56 | # Eclipse m2e
57 | .settings
58 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | ARG JAVA_VERSION=17
19 | ARG JAVA_REVISION=17.0.4
20 |
21 | FROM public.ecr.aws/amazoncorretto/amazoncorretto:${JAVA_REVISION}-al2
22 |
23 | COPY target/dependencies/* /var/runtime/lib/
24 |
25 | ENV LANG=en_US.UTF-8
26 | ENV TZ=:/etc/localtime
27 | ENV PATH=/opt/java/openjdk/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin
28 | ENV LD_LIBRARY_PATH=/lib:/usr/lib:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
29 | ENV LAMBDA_TASK_ROOT=/var/task
30 | ENV LAMBDA_RUNTIME_DIR=/var/runtime
31 |
32 | ENTRYPOINT [ "/usr/bin/java", "--class-path", "/var/runtime/lib/*:/var/task/lib/*:/var/task/", "--add-opens", "java.base/java.util=ALL-UNNAMED", "com.amazonaws.services.lambda.runtime.api.client.AWSLambda" ]
33 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AWS Lambda Java Base Images
2 |
3 | This project provides the missing [AWS Lambda base image](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-images.html) for Java 17, 18, 19, 20, and 21. The base images are publicly available [in the ECR Public Gallery](https://gallery.ecr.aws/aleph0io/lambda/java). You should be able to use them directly in your builds. I use these images in production for personal and commercial projects today, but per the license, there is no warranty, and YMMV.
4 |
5 | ## Approach
6 |
7 | This project uses the following process to create new Lambda base images:
8 |
9 | 1. Define a Java maven POM that includes all the [Java Lambda support libraries](https://github.com/aws/aws-lambda-java-libs) as provided scope. This roundabout approach is used to coax @dependabot into flagging new versions as they are published.
10 | 2. Also teach maven to collect these dependencies and build the appropriate docker images using a Dockerfile and the excellent [fabric8io/docker-maven-plugin](https://github.com/fabric8io/docker-maven-plugin).
11 | 3. Use GitHub Actions to perform CI/CD and release new images to the ECR Public Gallery.
12 |
13 | ## Example Lambda Function
14 |
15 | You can find an example Lambda function using these base images at [aleph0io/example-java-lambda-function](https://github.com/aleph0io/example-java-lambda-function). It's just like building any container lambda function. For ease of use, find the `Dockerfile` below. Note the `FROM` image. Java versions 17-20 are also supported.
16 |
17 | FROM public.ecr.aws/aleph0io/java/lambda:21-al2
18 |
19 | COPY target/hello-lambda.jar "${LAMBDA_TASK_ROOT}/lib/"
20 |
21 | CMD [ "com.sigpwned.lambda.hello.HelloLambda::handleRequest" ]
22 |
23 | ## Testing Lambda Functions Locally
24 |
25 | The [Lambda RIE](https://github.com/aws/aws-lambda-runtime-interface-emulator) is not currently built into these lambda base images, so to test your lambda function implementations locally, you will need to [use the standalone RIE server](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-add).
26 |
27 | ## Known Issues and Future Plans
28 |
29 | * This image is in no way optimized for cold start time, size, etc. PRs welcome!
30 | * Java 17, 18, 19, 20, and 21 are all supported.
31 | * For now, only x86_64 is supported. I hope to publish multiarch builds including arm64 soon.
32 | * Official base images for Java 17 have been released to [lambda/java](https://gallery.ecr.aws/lambda/java). Java 17 users should strongly consider moving to the officially-supported base images. This project will continue to release updates for Java 17 on an ongoing basis for those who prefer not to move.
33 | * This project will continue to support non-LTS Java versions that will never receive an officially-supported AWS Lambda base image.
34 |
35 | ## More Information
36 |
37 | You can find writeups of the [Java 17](https://sigpwned.com/2022/07/23/aws-lambda-base-images-for-java-17/), [18](https://sigpwned.com/2022/08/31/aws-lambda-base-images-for-java-18-too/), [19](https://sigpwned.com/2022/09/21/aws-lambda-base-images-for-java-19/), [20](https://sigpwned.com/2023/03/24/community-managed-aws-lambda-base-images-for-java-20/), and [21](https://sigpwned.com/2023/09/19/java-21-custom-runtime-for-aws-lambda/) on [my blog](https://sigpwned.com/).
38 |
39 | ## Acknowledgements
40 |
41 | Many thanks to [@rieckpil](https://github.com/rieckpil) for [his outstanding writeup of custom Lambda runtimes](https://rieckpil.de/java-aws-lambda-container-image-support-complete-guide/). That tutorial was the foundation and basis for this build. Cheers!
42 |
43 | Also, thank you to [@msailes](https://github.com/msailes) for [the example Java 17 Lambda layer](https://github.com/msailes/lambda-java17-layer). This prior art was also critically important to understanding how best to integrate a new Java version into Lambda.
44 |
45 | Managed by [@sigpwned](https://github.com/sigpwned).
46 |
--------------------------------------------------------------------------------
/cfn-build.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | AWSTemplateFormatVersion: 2010-09-09
19 |
20 | Resources:
21 | LambdaJavaBaseImageRepository:
22 | Type: AWS::ECR::PublicRepository
23 | Properties:
24 | RepositoryName: lambda/java
25 | RepositoryCatalogData:
26 | AboutText: |+
27 | Unofficial community base image for Lambda that contains all the required components to
28 | run your functions packaged as container images on AWS Lambda. This base image contains
29 | the Amazon Linux Base operating system, the runtime for Java, dependencies and the Lambda
30 | Runtime 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 | [aleph0io/aws-lambda-java-base-images](https://github.com/aleph0io/aws-lambda-java-base-images)
37 | on GitHub.
38 |
39 | Maintained by [@sigpwned](https://twitter.com/sigpwned). Drop me a line!
40 |
41 | ## Maintenance policy
42 |
43 | These images will be updated periodically to pick up new security patches. The components
44 | and dependencies included in the image may change from time to time, but they will always
45 | work for deploying images to AWS Lambda.
46 | UsageText: |-
47 | You can find an entire example AWS Lambda function implementation on GitHub at
48 | [aleph0io/example-java-lambda-function](https://github.com/aleph0io/example-java-lambda-function).
49 |
50 | Otherwise, you can get started by using these images in your Dockerfile and coping your
51 | class files into the `/var/task` folder in your image. The runtime jar dependencies should
52 | be copied into `/var/task/lib` directory.
53 |
54 | ```
55 | FROM public.ecr.aws/aleph0io/lambda/java:17
56 |
57 | # Copy function code and runtime dependencies from Gradle layout
58 | COPY build/classes/java/main ${LAMBDA_TASK_ROOT}
59 | COPY build/dependency/* ${LAMBDA_TASK_ROOT}/lib/
60 |
61 | # Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
62 | CMD [ "com.example.LambdaHandler::handleRequest" ]
63 | ```
64 |
65 | Example Gradle task definition to prepare the runtime dependencies:
66 |
67 | ```
68 | task copyRuntimeDependencies(type: Copy) {
69 | from configurations.runtimeClasspath
70 | into 'build/dependency'
71 | }
72 |
73 | build.dependsOn copyRuntimeDependencies
74 | ```
75 |
76 | If you are using Maven, adjust COPY command in the Dockerfile accordingly:
77 |
78 | ```
79 | FROM public.ecr.aws/aleph0io/lambda/java:17
80 |
81 | # Copy function code and runtime dependencies from Maven layout
82 | COPY target/classes ${LAMBDA_TASK_ROOT}
83 | COPY target/dependency/* ${LAMBDA_TASK_ROOT}/lib/
84 |
85 | # Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
86 | CMD [ "com.example.LambdaHandler::handleRequest" ]
87 | ```
88 |
89 | You can use maven-dependency-plugin to collect runtime dependencies:
90 |
91 | ```
92 |
93 |
94 |
95 | org.apache.maven.plugins
96 | maven-dependency-plugin
97 | 3.1.2
98 |
99 |
100 | copy-dependencies
101 | package
102 |
103 | copy-dependencies
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | ```
114 |
115 | Use `mvn compile dependency:copy-dependencies -DincludeScope=runtime` to compile the
116 | project and collect the runtime dependencies.
117 |
118 | The resulting layout should look like:
119 |
120 | /var/task/
121 | ├── com
122 | │ └── example
123 | │ ├── LambdaHandler.class
124 | │ └──
125 | └── lib
126 | ├── aws-lambda-java-core-1.2.1.jar
127 | ├── aws-lambda-java-events-3.7.0.jar
128 | └──
129 |
130 | You can then locally test your function using the docker build and docker run commands.
131 |
132 | To build your image:
133 |
134 | docker build -t .
135 |
136 | To run your image locally:
137 |
138 | docker run -p 9000:8080
139 |
140 | In a separate terminal, you can then locally invoke the function using cURL:
141 |
142 | curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
143 | RepositoryDescription: >
144 | Unofficial Community AWS Lambda Base Images for Java 17+
145 | OperatingSystems:
146 | - Linux
147 | Architectures:
148 | - x86-64
149 | Tags:
150 | - Key: aleph0
151 | Value: true
152 | - Key: aleph0:scope
153 | Value: public
154 | - Key: aleph0:role
155 | Value: lambda
156 |
157 | Outputs:
158 | JavaBaseImageRepositoryImageArn:
159 | Description: The ARN of the Java base image repository
160 | Value: !GetAtt LambdaJavaBaseImageRepository.Arn
161 | Export:
162 | Name: "lambda-java-base-image-arn"
163 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 | 4.0.0
21 |
22 | com.sigpwned
23 | aws-lambda-java-base-images
24 | 17.0.4
25 | aws-lambda-java-base-images
26 | 2022
27 | AWS Lambda Base Image for Java 17+
28 | https://github.com/sigpwned/aws-lambda-java-base-images
29 | jar
30 |
31 |
32 | Andy Boothe
33 | https://www.sigpwned.com/
34 |
35 |
36 |
37 | scm:git:ssh://git@github.com/sigpwned/aws-lambda-java-base-images.git
38 | scm:git:ssh://git@github.com/sigpwned/aws-lambda-java-base-images.git
39 | https://github.com/sigpwned/aws-lambda-java-base-images/tree/main
40 |
41 |
42 |
43 |
44 | Apache License, Version 2.0
45 | http://www.apache.org/licenses/LICENSE-2.0.txt
46 |
47 |
48 |
49 |
50 |
51 | Andy Boothe
52 | andy.boothe@gmail.com
53 |
54 |
55 |
56 |
57 | GitHub
58 | https://github.com/sigpwned/aws-lambda-java-base-images
59 |
60 |
61 |
62 | 17
63 | ${project.version}
64 | aleph0io
65 | al2
66 |
67 |
68 |
69 |
70 |
71 | org.apache.maven.plugins
72 | maven-dependency-plugin
73 | 3.5.0
74 |
75 | ${project.build.directory}/dependencies
76 |
77 |
78 |
79 | io.fabric8
80 | docker-maven-plugin
81 | 0.43.4
82 |
83 |
84 | docker-build
85 |
86 | build
87 |
88 | package
89 |
90 |
91 | docker-push
92 |
93 | push
94 |
95 | deploy
96 |
97 |
98 |
99 |
100 |
101 |
102 | ${project.basedir}
103 |
104 | ${java.version}
105 | ${java.revision}
106 |
107 |
108 | ${java.version}
109 | ${java.version}-${os.platform}
110 | ${java.revision}
111 | ${java.revision}-${os.platform}
112 |
113 |
114 | ${java.version}
115 | ${java.revision}
116 | ${os.platform}
117 |
118 |
119 | public.ecr.aws/${aws.registry}/lambda/java
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 | com.amazonaws
130 | aws-lambda-java-core
131 | 1.2.3
132 | provided
133 |
134 |
135 | com.amazonaws
136 | aws-lambda-java-serialization
137 | 1.1.3
138 | provided
139 |
140 |
141 | com.amazonaws
142 | aws-lambda-java-runtime-interface-client
143 | 2.4.1
144 | provided
145 |
146 |
147 | com.amazonaws
148 | aws-lambda-java-log4j2
149 | 1.5.1
150 | provided
151 |
152 |
153 | com.amazonaws
154 | aws-lambda-java-events
155 | 3.11.3
156 | provided
157 |
158 |
159 | com.amazonaws
160 | aws-lambda-java-events-sdk-transformer
161 | 3.1.0
162 | provided
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------