Developing Web Services on AWS Lambda with Java
Coding > May 2026 · Peerapat A ·
Bottom Line Up Front: Developing serverless Web Services on AWS Lambda with Java requires creating an IAM execution role and deploying a Java function. This guide provides step-by-step instructions and example code to get your Java 11 Lambda function up and running quickly.
1. To create an execution role
- Open the roles page in the IAM console.
- Choose Create role.
- Create a role with the following properties.
- Trusted entity – Lambda.
- Permissions – AWSLambdaBasicExecutionRole.
- Role name – lambda-role.
The AWSLambdaBasicExecutionRole policy has the permissions that the function needs to write logs to CloudWatch Logs. You can add permissions to the role later, or swap it out for a different role that's specific to a single function.
2. To create a Java function
- Open the Lambda console.
- Choose Create function.
- Configure the following settings:
- Name – my-function.
- Runtime – Java 11.
- Role – Choose an existing role.
- Existing role – lambda-role.
- Choose Create function.
- To configure a test event, choose Test.
- For Event name, enter test.
- Choose Save changes.
- To invoke the function, choose Test.
พัฒนา Web Services บน AWS Lambda ด้วยภาษา Java
May 2026 · Peerapat A · ← Coding
สรุปประเด็นสำคัญ (BLUF): การพัฒนา serverless Web Services บน AWS Lambda ด้วยภาษา Java ต้องอาศัยการสร้าง IAM execution role และ deploy Java function บทความนี้ให้คำแนะนำทีละขั้นตอนและมีโค้ดตัวอย่างเพื่อให้ Java 11 Lambda function ของคุณทำงานได้อย่างรวดเร็ว
1. การสร้าง execution role
- เปิดหน้า roles ใน IAM console
- เลือก Create role
- สร้าง role โดยกำหนด properties ดังนี้
- Trusted entity – Lambda
- Permissions – AWSLambdaBasicExecutionRole
- Role name – lambda-role
Policy AWSLambdaBasicExecutionRole มี permissions ที่ function ต้องการเพื่อใช้ในการเขียน logs ลงใน CloudWatch Logs คุณสามารถเพิ่ม permissions ให้กับ role ได้ในภายหลัง หรือเปลี่ยนไปใช้ role อื่นที่สร้างขึ้นสำหรับ function เดียวโดยเฉพาะ
2. การสร้าง Java function
- เปิด Lambda console
- เลือก Create function
- Configure การตั้งค่าต่อไปนี้:
- Name – my-function
- Runtime – Java 11
- Role – Choose an existing role
- Existing role – lambda-role
- เลือก Create function
- เพื่อ configure test event ให้เลือก Test
- สำหรับ Event name ให้ใส่ test
- เลือก Save changes
- หากต้องการ invoke function ให้เลือก Test
使用 Java 在 AWS Lambda 上开发 Web Services
May 2026 · Peerapat A · ← Coding
核心结论 (BLUF): 使用 Java 在 AWS Lambda 上开发无服务器 Web Services 需要创建 IAM execution role 并部署 Java function。本指南提供分步说明和代码示例,帮助你快速启动并运行 Java 11 Lambda function。
1. 创建 execution role
- 在 IAM console 中打开 roles 页面。
- 选择 Create role。
- 使用以下 properties 创建 role。
- Trusted entity – Lambda。
- Permissions – AWSLambdaBasicExecutionRole。
- Role name – lambda-role。
AWSLambdaBasicExecutionRole policy 具有 function 将 logs 写入 CloudWatch Logs 所需的 permissions。你可以在之后向 role 添加 permissions,或将其替换为特定于单个 function 的其他 role。
2. 创建 Java function
- 打开 Lambda console。
- 选择 Create function。
- Configure 以下设置:
- Name – my-function。
- Runtime – Java 11。
- Role – Choose an existing role。
- Existing role – lambda-role。
- 选择 Create function。
- 要 configure test event,请选择 Test。
- 对于 Event name,输入 test。
- 选择 Save changes。
- 要 invoke 你的 function,请选择 Test。
Java を使用した AWS Lambda 上の Web Services 開発
May 2026 · Peerapat A · ← Coding
要点 (BLUF): Java を使用して AWS Lambda 上でサーバーレス Web Services を開発するには、IAM execution role を作成し、Java function をデプロイする必要があります。このガイドでは、Java 11 Lambda function を迅速にセットアップして実行するための段階的な手順とコード例を提供します。
1. execution role の作成
- IAM console で roles ページを開きます。
- Create role を選択します。
- 次の properties で role を作成します。
- Trusted entity – Lambda。
- Permissions – AWSLambdaBasicExecutionRole。
- Role name – lambda-role。
AWSLambdaBasicExecutionRole policy には、function が CloudWatch Logs に logs を書き込むために必要な permissions が含まれています。後で role に permissions を追加したり、単一の function 固有の別の role に入れ替えたりすることができます。
2. Java function の作成
- Lambda console を開きます。
- Create function を選択します。
- 次の設定を configure します:
- Name – my-function。
- Runtime – Java 11。
- Role – Choose an existing role。
- Existing role – lambda-role。
- Create function を選択します。
- test event を configure するには、Test を選択します。
- Event name に test と入力します。
- Save changes を選択します。
- function を invoke するには、Test を選択します。
Entwicklung von Web Services auf AWS Lambda mit Java
May 2026 · Peerapat A · ← Coding
Zusammenfassung (BLUF): Die Entwicklung serverloser Web Services auf AWS Lambda mit Java erfordert die Erstellung einer IAM execution role und die Bereitstellung einer Java function. Diese Anleitung bietet Schritt-für-Schritt-Anweisungen und Beispielcode, damit Ihre Java 11 Lambda function schnell einsatzbereit ist.
1. Erstellen einer execution role
- Öffnen Sie die roles-Seite in der IAM console.
- Wählen Sie Create role.
- Erstellen Sie eine role mit den folgenden properties:
- Trusted entity – Lambda.
- Permissions – AWSLambdaBasicExecutionRole.
- Role name – lambda-role.
Die AWSLambdaBasicExecutionRole policy enthält die permissions, die die function benötigt, um logs in CloudWatch Logs zu schreiben. Sie können der role später permissions hinzufügen oder sie gegen eine andere role austauschen, die spezifisch für eine einzelne function ist.
2. Erstellen einer Java function
- Öffnen Sie die Lambda console.
- Wählen Sie Create function.
- Configure die folgenden Einstellungen:
- Name – my-function.
- Runtime – Java 11.
- Role – Choose an existing role.
- Existing role – lambda-role.
- Wählen Sie Create function.
- Um ein test event zu configure, wählen Sie Test.
- Geben Sie für den Event name test ein.
- Wählen Sie Save changes.
- Um die function zu invoke, wählen Sie Test.
Example Code
package cc.peerapat;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPResponse;
import java.util.HashMap;
import java.util.Map;
/**
* cc.peerapat.BahtTextHTTP::handleRequest
*/
public class BahtTextHTTP
implements RequestHandler<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse> {
final Map<String, String> headers = new HashMap<>();
public BahtTextHTTP() {
headers.put("Content-Type", "text/plain");
}
@Override
public APIGatewayV2HTTPResponse handleRequest(
final APIGatewayV2HTTPEvent request
, final Context context) {
return buildResponse(BahtText.toText(request.getBody()));
}
private APIGatewayV2HTTPResponse buildResponse(final String body) {
var response = new APIGatewayV2HTTPResponse();
response.setIsBase64Encoded(false);
response.setStatusCode(200);
response.setHeaders(headers);
response.setBody(body);
return response;
}
}
© peerapat.cc