aws-sdk-java-v2-lambda by giuseppe-trisciuoglio/developer-kit
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill aws-sdk-java-v2-lambdaAWS Lambda 是一项无需管理服务器即可运行代码的计算服务。使用此技能可在应用程序和服务中通过 AWS SDK for Java 2.x 实现 AWS Lambda 操作。
| 操作 | SDK 方法 | 使用场景 |
|---|---|---|
| 调用 | invoke() | 同步/异步函数调用 |
| 列出函数 | listFunctions() | 获取所有 Lambda 函数 |
| 获取配置 | getFunction() |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 检索函数配置 |
| 创建函数 | createFunction() | 创建新的 Lambda 函数 |
| 更新代码 | updateFunctionCode() | 部署新的函数代码 |
| 更新配置 | updateFunctionConfiguration() | 修改设置(超时、内存、环境变量) |
| 删除函数 | deleteFunction() | 移除 Lambda 函数 |
在 pom.xml 中包含 Lambda SDK 依赖:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>lambda</artifactId>
</dependency>
完整设置请参阅 client-setup.md。
使用适当的配置实例化 LambdaClient:
LambdaClient lambdaClient = LambdaClient.builder()
.region(Region.US_EAST_1)
.build();
对于异步操作,请使用 LambdaAsyncClient。
同步调用:
InvokeRequest request = InvokeRequest.builder()
.functionName("my-function")
.payload(SdkBytes.fromUtf8String(payload))
.build();
InvokeResponse response = lambdaClient.invoke(request);
return response.payload().asUtf8String();
调用模式请参阅 invocation-patterns.md。
解析响应负载并检查错误:
if (response.functionError() != null) {
throw new LambdaInvocationException("Lambda error: " + response.functionError());
}
String result = response.payload().asUtf8String();
创建、更新或删除 Lambda 函数:
// 创建
CreateFunctionRequest createRequest = CreateFunctionRequest.builder()
.functionName("my-function")
.runtime(Runtime.JAVA17)
.role(roleArn)
.code(code)
.build();
lambdaClient.createFunction(createRequest);
// 在继续之前验证函数是否处于活动状态
GetFunctionRequest getRequest = GetFunctionRequest.builder()
.functionName("my-function")
.build();
GetFunctionResponse getResponse = lambdaClient.getFunction(getRequest);
if (!"Active".equals(getResponse.configuration().state())) {
throw new IllegalStateException("Function not active: " + getResponse.configuration().stateReason());
}
// 更新代码
UpdateFunctionCodeRequest updateCodeRequest = UpdateFunctionCodeRequest.builder()
.functionName("my-function")
.zipFile(SdkBytes.fromByteArray(zipBytes))
.build();
lambdaClient.updateFunctionCode(updateCodeRequest);
// 等待部署完成
Waiter<GetFunctionConfigurationRequest> waiter = lambdaClient.waiter();
waiter.waitUntilFunctionUpdatedActive(GetFunctionConfigurationRequest.builder()
.functionName("my-function")
.build());
完整模式请参阅 function-management.md。
设置环境变量和并发限制:
Environment env = Environment.builder()
.variables(Map.of(
"DB_URL", "jdbc:postgresql://db",
"LOG_LEVEL", "INFO"
))
.build();
UpdateFunctionConfigurationRequest configRequest = UpdateFunctionConfigurationRequest.builder()
.functionName("my-function")
.environment(env)
.timeout(60)
.memorySize(512)
.build();
lambdaClient.updateFunctionConfiguration(configRequest);
配置 Lambda Bean 和服务:
@Configuration
public class LambdaConfiguration {
@Bean
public LambdaClient lambdaClient() {
return LambdaClient.builder()
.region(Region.US_EAST_1)
.build();
}
}
@Service
public class LambdaInvokerService {
public <T, R> R invoke(String functionName, T request, Class<R> responseType) {
// 实现
}
}
完整集成请参阅 spring-boot-integration.md。
使用模拟或 LocalStack 进行开发测试。
测试模式请参阅 testing.md。
public String invokeFunction(LambdaClient client, String functionName, String payload) {
InvokeRequest request = InvokeRequest.builder()
.functionName(functionName)
.payload(SdkBytes.fromUtf8String(payload))
.build();
InvokeResponse response = client.invoke(request);
if (response.functionError() != null) {
throw new RuntimeException("Lambda error: " + response.functionError());
}
return response.payload().asUtf8String();
}
public void invokeAsync(LambdaClient client, String functionName, Map<String, Object> event) {
String jsonPayload = new ObjectMapper().writeValueAsString(event);
InvokeRequest request = InvokeRequest.builder()
.functionName(functionName)
.invocationType(InvocationType.EVENT)
.payload(SdkBytes.fromUtf8String(jsonPayload))
.build();
client.invoke(request);
}
@Service
public class LambdaService {
private final LambdaClient lambdaClient;
public UserResponse processUser(UserRequest request) {
String payload = objectMapper.writeValueAsString(request);
InvokeResponse response = lambdaClient.invoke(
InvokeRequest.builder()
.functionName("user-processor")
.payload(SdkBytes.fromUtf8String(payload))
.build()
);
return objectMapper.readValue(
response.payload().asUtf8String(),
UserResponse.class
);
}
}
更多示例请参阅 examples.md。
LambdaClient/LambdaAsyncClient;它们是线程安全的CompletableFuture 的 LambdaAsyncClientActiveRuntime.JAVA17 或更高版本以获得更好的冷启动性能aws-sdk-java-v2-core — 核心 AWS SDK 模式和客户端配置spring-boot-dependency-injection — Spring 依赖注入最佳实践unit-test-service-layer — 使用 Mockito 的服务测试模式spring-boot-actuator — 生产环境监控和健康检查每周安装数
333
代码仓库
GitHub 星标数
173
首次出现
2026年2月3日
安全审计
安装于
claude-code270
gemini-cli253
cursor253
opencode252
codex247
github-copilot232
AWS Lambda is a compute service that runs code without managing servers. Use this skill to implement AWS Lambda operations using AWS SDK for Java 2.x in applications and services.
| Operation | SDK Method | Use Case |
|---|---|---|
| Invoke | invoke() | Synchronous/async function invocation |
| List Functions | listFunctions() | Get all Lambda functions |
| Get Config | getFunction() | Retrieve function configuration |
| Create Function | createFunction() | Create new Lambda function |
| Update Code | updateFunctionCode() | Deploy new function code |
| Update Config | updateFunctionConfiguration() | Modify settings (timeout, memory, env vars) |
| Delete Function | deleteFunction() | Remove Lambda function |
Include Lambda SDK dependency in pom.xml:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>lambda</artifactId>
</dependency>
See client-setup.md for complete setup.
Instantiate LambdaClient with proper configuration:
LambdaClient lambdaClient = LambdaClient.builder()
.region(Region.US_EAST_1)
.build();
For async operations, use LambdaAsyncClient.
Synchronous invocation:
InvokeRequest request = InvokeRequest.builder()
.functionName("my-function")
.payload(SdkBytes.fromUtf8String(payload))
.build();
InvokeResponse response = lambdaClient.invoke(request);
return response.payload().asUtf8String();
See invocation-patterns.md for patterns.
Parse response payloads and check for errors:
if (response.functionError() != null) {
throw new LambdaInvocationException("Lambda error: " + response.functionError());
}
String result = response.payload().asUtf8String();
Create, update, or delete Lambda functions:
// Create
CreateFunctionRequest createRequest = CreateFunctionRequest.builder()
.functionName("my-function")
.runtime(Runtime.JAVA17)
.role(roleArn)
.code(code)
.build();
lambdaClient.createFunction(createRequest);
// Verify function is active before proceeding
GetFunctionRequest getRequest = GetFunctionRequest.builder()
.functionName("my-function")
.build();
GetFunctionResponse getResponse = lambdaClient.getFunction(getRequest);
if (!"Active".equals(getResponse.configuration().state())) {
throw new IllegalStateException("Function not active: " + getResponse.configuration().stateReason());
}
// Update code
UpdateFunctionCodeRequest updateCodeRequest = UpdateFunctionCodeRequest.builder()
.functionName("my-function")
.zipFile(SdkBytes.fromByteArray(zipBytes))
.build();
lambdaClient.updateFunctionCode(updateCodeRequest);
// Wait for deployment to complete
Waiter<GetFunctionConfigurationRequest> waiter = lambdaClient.waiter();
waiter.waitUntilFunctionUpdatedActive(GetFunctionConfigurationRequest.builder()
.functionName("my-function")
.build());
See function-management.md for complete patterns.
Set environment variables and concurrency limits:
Environment env = Environment.builder()
.variables(Map.of(
"DB_URL", "jdbc:postgresql://db",
"LOG_LEVEL", "INFO"
))
.build();
UpdateFunctionConfigurationRequest configRequest = UpdateFunctionConfigurationRequest.builder()
.functionName("my-function")
.environment(env)
.timeout(60)
.memorySize(512)
.build();
lambdaClient.updateFunctionConfiguration(configRequest);
Configure Lambda beans and services:
@Configuration
public class LambdaConfiguration {
@Bean
public LambdaClient lambdaClient() {
return LambdaClient.builder()
.region(Region.US_EAST_1)
.build();
}
}
@Service
public class LambdaInvokerService {
public <T, R> R invoke(String functionName, T request, Class<R> responseType) {
// Implementation
}
}
See spring-boot-integration.md for complete integration.
Use mocks or LocalStack for development testing.
See testing.md for testing patterns.
public String invokeFunction(LambdaClient client, String functionName, String payload) {
InvokeRequest request = InvokeRequest.builder()
.functionName(functionName)
.payload(SdkBytes.fromUtf8String(payload))
.build();
InvokeResponse response = client.invoke(request);
if (response.functionError() != null) {
throw new RuntimeException("Lambda error: " + response.functionError());
}
return response.payload().asUtf8String();
}
public void invokeAsync(LambdaClient client, String functionName, Map<String, Object> event) {
String jsonPayload = new ObjectMapper().writeValueAsString(event);
InvokeRequest request = InvokeRequest.builder()
.functionName(functionName)
.invocationType(InvocationType.EVENT)
.payload(SdkBytes.fromUtf8String(jsonPayload))
.build();
client.invoke(request);
}
@Service
public class LambdaService {
private final LambdaClient lambdaClient;
public UserResponse processUser(UserRequest request) {
String payload = objectMapper.writeValueAsString(request);
InvokeResponse response = lambdaClient.invoke(
InvokeRequest.builder()
.functionName("user-processor")
.payload(SdkBytes.fromUtf8String(payload))
.build()
);
return objectMapper.readValue(
response.payload().asUtf8String(),
UserResponse.class
);
}
}
See examples.md for more examples.
LambdaClient/LambdaAsyncClient once; they are thread-safeLambdaAsyncClient with CompletableFutureActive after create/update operationsRuntime.JAVA17 or newer for improved cold start performanceaws-sdk-java-v2-core — Core AWS SDK patterns and client configurationspring-boot-dependency-injection — Spring dependency injection best practicesunit-test-service-layer — Service testing patterns with Mockitospring-boot-actuator — Production monitoring and health checksWeekly Installs
333
Repository
GitHub Stars
173
First Seen
Feb 3, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code270
gemini-cli253
cursor253
opencode252
codex247
github-copilot232
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
106,200 周安装