Skip to content

giuseppe-trisciuoglio/developer-kit / plugins/developer-kit-java/skills/aws-sdk-java-v2-lambda

aws-sdk-java-v2-lambda

Unverified

Provides AWS Lambda patterns using AWS SDK for Java 2.x. Use when invoking Lambda functions, creating/updating functions, managing function configurations, working with Lambda layers, or integrating Lambda with Spring Boot applications.

references/spring-boot-integration.md

View on GitHub
# Spring Boot Integration

## Configuration

```java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LambdaConfiguration {

    @Bean
    public LambdaClient lambdaClient() {
        return LambdaClient.builder()
            .region(Region.US_EAST_1)
            .build();
    }

    @Bean
    public LambdaAsyncClient lambdaAsyncClient() {
        return LambdaAsyncClient.builder()
            .region(Region.US_EAST_1)
            .build();
    }

    @Bean
    public ObjectMapper lambdaObjectMapper() {
        return new ObjectMapper();
            .registerModules(new JavaTimeModule())
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    }
}
```

## Lambda Invoker Service

```java
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class LambdaInvokerService {

    private final LambdaClient lambdaClient;
    private final ObjectMapper objectMapper;

    public <T, R> R invoke(String functionName, T request, Class<R> responseType) {
        try {
            String jsonPayload = objectMapper.writeValueAsString(request);

            InvokeRequest invokeRequest = InvokeRequest.builder()
                .functionName(functionName)
                .payload(SdkBytes.fromUtf8String(jsonPayload))
                .build();

            InvokeResponse response = lambdaClient.invoke(invokeRequest);

            if (response.functionError() != null) {
                throw new LambdaInvocationException(
                    "Lambda function error: " + response.functionError());
            }

            if (response.statusCode() != 200) {
                throw new LambdaInvocationException(
                    functionName,
                    String.valueOf(response.statusCode()),
                    "Lambda invocation failed"
                );
            }

            String responseJson = response.payload().asUtf8String();

            return objectMapper.readValue(responseJson, responseType);

        } catch (Exception e) {
            throw new RuntimeException("Failed to invoke Lambda function", e);
        }
    }

    public void invokeAsync(String functionName, Object request) {
        try {
            String jsonPayload = objectMapper.writeValueAsString(request);

            InvokeRequest invokeRequest = InvokeRequest.builder()
                .functionName(functionName)
                .invocationType(InvocationType.EVENT)
                .payload(SdkBytes.fromUtf8String(jsonPayload))
                .build();

            lambdaClient.invoke(invokeRequest);

        } catch (Exception e) {
            throw new RuntimeException("Failed to invoke Lambda function async", e);
        }
    }

    public String invokeRaw(String functionName, String payload) {
        try {
            InvokeRequest invokeRequest = InvokeRequest.builder()
                .functionName(functionName)
                .payload(SdkBytes.fromUtf8String(payload))
                .build();

            InvokeResponse response = lambdaClient.invoke(invokeRequest);

            if (response.functionError() != null) {
                throw new LambdaInvocationException(
                    "Lambda function error: " + response.functionError());
            }

            return response.payload().asUtf8String();

        } catch (Exception e) {
            throw new RuntimeException("Failed to invoke Lambda function", e);
        }
    }
}
```

## Typed Lambda Client

```java
public interface OrderProcessor {
    OrderResponse processOrder(OrderRequest request);
}

@Service
public class LambdaOrderProcessor implements OrderProcessor {

    private final LambdaInvokerService lambdaInvoker;

    @Value("${lambda.order-processor.function-name}")
    private String functionName;

    public LambdaOrderProcessor(LambdaInvokerService lambdaInvoker) {
        this.lambdaInvoker = lambdaInvoker;
    }

    @Override
    public OrderResponse processOrder(OrderRequest request) {
        return lambdaInvoker.invoke(functionName, request, OrderResponse.class);
    }
}
```

## Configuration Properties

```java
@Configuration
@ConfigurationProperties(prefix = "lambda")
@Data
public class LambdaProperties {
    private Map<String, FunctionConfig> functions = new HashMap<>();

    @Data
    public static class FunctionConfig {
        private String functionName;
        private String region;
        private Integer timeout;
        private Integer memorySize;
        private Map<String, String> environment = new HashMap<>();
    }
}
```

## Application Properties

```yaml
lambda:
  functions:
    order-processor:
      function-name: ${ORDER_PROCESSOR_FUNCTION:order-processor-dev}
      region: ${AWS_REGION:us-east-1}
      timeout: 60
      memory-size: 512
      environment:
        LOG_LEVEL: INFO
    user-processor:
      function-name: ${USER_PROCESSOR_FUNCTION:user-processor-dev}
      region: ${AWS_REGION:us-east-1}
      timeout: 30
      memory-size: 256
```

## Dynamic Lambda Service

```java
@Service
public class DynamicLambdaService {

    private final LambdaClient lambdaClient;
    private final LambdaProperties lambdaProperties;

    public <T, R> R invoke(String functionKey, T request, Class<R> responseType) {
        LambdaProperties.FunctionConfig config = lambdaProperties.getFunctions()
            .get(functionKey);

        if (config == null) {
            throw new IllegalArgumentException("Unknown function key: " + functionKey);
        }

        return invokeLambda(config, request, responseType);
    }

    private <T, R> R invokeLambda(LambdaProperties.FunctionConfig config,
                                   T request,
                                   Class<R> responseType) {
        try {
            String jsonPayload = objectMapper.writeValueAsString(request);

            InvokeRequest invokeRequest = InvokeRequest.builder()
                .functionName(config.getFunctionName())
                .payload(SdkBytes.fromUtf8String(jsonPayload))
                .build();

            InvokeResponse response = lambdaClient.invoke(invokeRequest);

            String responseJson = response.payload().asUtf8String();

            return objectMapper.readValue(responseJson, responseType);

        } catch (Exception e) {
            throw new RuntimeException("Failed to invoke Lambda", e);
        }
    }
}
```

## Async Lambda Service

```java
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.concurrent.CompletableFuture;

@Service
public class AsyncLambdaService {

    private final LambdaAsyncClient asyncClient;

    @Async
    public CompletableFuture<String> invokeAsync(String functionName,
                                                 String payload) {
        return CompletableFuture.supplyAsync(() -> {
            try {
                String jsonPayload = objectMapper.writeValueAsString(payload);

                InvokeRequest request = InvokeRequest.builder()
                    .functionName(functionName)
                    .payload(SdkBytes.fromUtf8String(jsonPayload))
                    .build();

                InvokeResponse response = asyncClient.invoke(request).get();

                return response.payload().asUtf8String();

            } catch (Exception e) {
                throw new RuntimeException("Async invocation failed", e);
            }
        });
    }
}
```

## Health Check

```java
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class LambdaHealthIndicator implements HealthIndicator {

    private final LambdaClient lambdaClient;

    @Override
    public Health health() {
        try {
            ListFunctionsResponse response = lambdaClient.listFunctions();
            return Health.up()
                .withDetail("functions", response.functions().size())
                .build();
        } catch (Exception e) {
            return Health.down()
                .withDetail("error", e.getMessage())
                .build();
        }
    }
}
```
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 318kUpdated Claude CodeCodexUnverifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 117kUpdated Claude CodeCodexUnverifiedInstall