[アップデート] AWS Lambda が Java 25 をサポートしたので、SAM CLI でデプロイしてみた
いわさです。
ここ数日で Lambda のランタイム周りに色々アップデートが来ていますね。
その流れで 9 月 にリリースされた Java 25[1] もサポートされました。
そして、AWS SAM CLI も v1.146.0 で Java 25 がデプロイできるようになっています。
またsam initの一部テンプレートでも早速 Java 25 がサポートされています。
今回は SAM CLI を使って Java 25 を使った Lambda 関数をデプロイしてみましたのでその様子を紹介します。
コンソールでの Java 25 Lambda 関数の作成
マネジメントコンソールで作成する場合は次のとおりで関数作成時に新しく「Java 25」を選択できるようになっていますのでこちらを選択するだけです。

SAM CLI での Java 25 Lambda 関数の作成
SAM CLI のバージョンは 1.146.0 から利用できます。
事前にローカルの SAM CLI をアップデートしておきます。
% sam --version
SAM CLI, version 1.146.0
また、sam buildの際にエラーが起きるのでローカルの Java バージョンも上げておきます。
これを忘れて最初 Gradle ビルド時のエラーが出ました。
% java --version
openjdk 25.0.1 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)
あとはsam initでテンプレートを選択します。
% sam init -a arm64
Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1
Choose an AWS Quick Start application template
1 - Hello World Example
2 - Data processing
3 - Hello World Example with Powertools for AWS Lambda
4 - Multi-step workflow
5 - Scheduled task
6 - Standalone function
7 - Serverless API
8 - Infrastructure event management
9 - Lambda Response Streaming
10 - GraphQLApi Hello World Example
11 - Full Stack
12 - Lambda EFS example
13 - Serverless Connector Hello World Example
14 - Multi-step workflow with Connectors
15 - DynamoDB Example
16 - Machine Learning
Template: 1
Use the most popular runtime and package type? (python3.14 and zip) [y/N]:
Which runtime would you like to use?
1 - dotnet8
2 - dotnet6
3 - go (provided.al2)
4 - go (provided.al2023)
5 - graalvm.java11 (provided.al2)
6 - graalvm.java17 (provided.al2)
7 - java25
8 - java21
9 - java17
10 - java11
11 - java8.al2
12 - nodejs22.x
13 - nodejs20.x
14 - python3.9
15 - python3.14
16 - python3.13
17 - python3.12
18 - python3.11
19 - python3.10
20 - ruby3.4
21 - ruby3.3
22 - ruby3.2
23 - rust (provided.al2)
24 - rust (provided.al2023)
7 - java25が追加されていますね!
このあとは割愛しますが上記を選択して一式を作成します。今回はビルドツールは Gradle を選択しました。
作成されたテンプレートを確認してみましょう。
:
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.App::handleRequest
Runtime: java25
Architectures:
- arm64
MemorySize: 512
Environment:
Variables:
PARAM1: VALUE
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
:
Runtime: java25が指定されていますね。
build.gradleはこんな感じです。
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.amazonaws:aws-lambda-java-core:1.2.2'
implementation 'com.amazonaws:aws-lambda-java-events:3.11.0'
testImplementation 'junit:junit:4.13.2'
}
java {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}
ではビルドしてみましょう。ローカル環境の Java バージョンが更新されていれば無事ビルドできるはず...
% sam build
Starting Build use cache
Cache is invalid, running build and copying resources for following functions
(HelloWorldFunction)
Building codeuri:
/Users/iwasa.takahito/work/hoge1118java25/hoge1118java/HelloWorldFunction runtime:
java25 architecture: arm64 functions: HelloWorldFunction
Running JavaGradleWorkflow:GradleBuild
Running JavaGradleWorkflow:JavaGradleCopyArtifacts
Running JavaGradleWorkflow:CleanUp
Running JavaGradleWorkflow:JavaCopyDependencies
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
%
ビルドうまくいきましたね。このままデプロイまでしちゃいます。
% sam deploy
Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-b2ke18r5t3j
Auto resolution of buckets can be turned off by setting resolve_s3=False
To use a specific S3 bucket, set --s3-bucket=<bucket_name>
Above settings can be stored in samconfig.toml
Uploading to 06f00bf5c3b33c7f7b636116e6475607 875090 / 875090 (100.00%)
Deploying with following values
===============================
Stack name : hoge1118java
Region : ap-northeast-1
Confirm changeset : True
Disable rollback : False
Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-b2ke18r5t3j
Capabilities : ["CAPABILITY_IAM"]
Parameter overrides : {}
Signing Profiles : {}
Initiating deployment
=====================
Uploading to 241b6950a4f55a50f0370d4259fbe113.template 1296 / 1296 (100.00%)
:
Successfully created/updated stack - hoge1118java in ap-northeast-1
できました。
マネジメントコンソールから確認してみます。

こちらが今デプロイされた関数です。ランタイムが Java 25 になっていますね。
実行も問題なくできます。

コード変更
コードを変更してランタイムの情報を少し確認してみます。
App.javaのコードを少し追加しましょう。
package helloworld;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
/**
* Handler for requests to Lambda function.
*/
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("X-Custom-Header", "application/json");
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
.withHeaders(headers);
try {
final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
+ final String javaVersion = System.getProperty("java.version");
+ final String javaVendor = System.getProperty("java.vendor");
+ String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\", \"javaVersion\": \"%s\", \"javaVendor\": \"%s\" }",
+ pageContents, javaVersion, javaVendor);
return response
.withStatusCode(200)
.withBody(output);
} catch (IOException e) {
return response
.withBody("{}")
.withStatusCode(500);
}
}
private String getPageContents(String address) throws IOException{
URL url = new URL(address);
try(BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
return br.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
}
こちらを再度sam build → sam deployします。
更新された関数をテスト実行してみます。

実行環境の情報を少し確認出来ましたね。
25.0.1 で実行されており、Amazon Corretto が使われているようです。
今回確認していませんが、Java 21 以降は OS は AL2 ではなく AL2023 になっているのでそこはおそらく同じでしょう。
さいごに
本日は AWS Lambda が Java 25 をサポートしたので、SAM CLI でデプロイしてみました。
Java の最新機能を使いたい方はぜひ試してみてください。
Lambda Java 11 & 17 の廃止が 2026 年 6 月 30 日、Lambda Java 21 の廃止が 2029 年 6 月 30 日の予定になっています。[2]
計画的にアップデートしましょう。







