aws / aws/serverless-java-container

Make fields from com.amazonaws.serverless.proxy.model.AwsProxyRequest optional to set

Abierto
#1,495 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
1.6k
Forks
574
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

When using AWS Serverless Java Container with Spring Boot 3 and Lambda SnapStart with priming with I tested this type of priming implementation [WebRequestPriming](https://github.com/Vadym79/AWSLambdaJavaWithSpringBoot/blob/master/spring-boot-3.4-with-aws-serverless-java-container/src/main/java/software/amazonaws/example/product/handler/StreamLambdaHandlerWithWebRequestPriming.javal)

Unfortunately I have to set so many fields of the com.amazonaws.serverless.proxy.model.AwsProxyRequest with dummy values and even create dummy objects like AwsProxyRequestContext and ApiGatewayRequestIdentity (see the method **getAwsProxyRequest**) in order not to get errors like:

at
com.amazonaws.serverless.exceptions.InvalidRequestEventException: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)

or

java.lang.NullPointerException: Cannot invoke "com.amazonaws.serverless.proxy.model.ApiGatewayRequestIdentity.getAccessKey()" because the return value of "com.amazonaws.serverless.proxy.model.AwsProxyRequestContext.getIdentity()" is null

Here is the complete code I had to write in order to make it work:

private static AwsProxyRequest getAwsProxyRequest () {
final AwsProxyRequest awsProxyRequest = new AwsProxyRequest ();
awsProxyRequest.setHttpMethod("GET");
awsProxyRequest.setPath("/products/0");
//awsProxyRequest.setResource("/products/{id}");
awsProxyRequest.setPathParameters(Map.of("id","0"));
final AwsProxyRequestContext awsProxyRequestContext = new AwsProxyRequestContext();
final ApiGatewayRequestIdentity apiGatewayRequestIdentity= new ApiGatewayRequestIdentity();
apiGatewayRequestIdentity.setApiKey("blabla");
awsProxyRequestContext.setIdentity(apiGatewayRequestIdentity);
awsProxyRequest.setRequestContext(awsProxyRequestContext);
return awsProxyRequest;
}

For my use case this will be enough to do the priming like this:

final AwsProxyRequest awsProxyRequest = new AwsProxyRequest ();
awsProxyRequest.setHttpMethod("GET");
awsProxyRequest.setPathParameters(Map.of("id","0"));

Others, that priming Post request would only like to set the body like this:

final AwsProxyRequest awsProxyRequest = new AwsProxyRequest ();
awsProxyRequest.setHttpMethod("POST");
awsProxyRequest.setBody("bla");

Many field should be optional to set to easily construct such objects or please provide static factory methods for it to save on the boilerplate code.

Compare it with how easy it is to implement the same type of SnapStart priming with

1) Spring Cloud Function AWS Adapter

see my implementation of the method **getAPIGatewayProxyRequestEventAsJson** here [AmazonAPIGatewayPrimingResource](https://github.com/Vadym79/AWSLambdaJavaWithSpringBoot/blob/master/spring-boot-3.4-with-spring-cloud-function/src/main/java/software/amazonaws/example/product/handler/GetProductByIdWithWebRequestPrimingHandler.javal)

as I only do

final APIGatewayProxyRequestEvent proxyRequestEvent = new APIGatewayProxyRequestEvent ();
proxyRequestEvent.setHttpMethod("GET");
proxyRequestEvent.setPathParameters(Map.of("id","0"));

2) Quarkus 3, see my implementation of the method **getAwsProxyRequest** here [AmazonAPIGatewayPrimingResource](https://github.com/Vadym79/AWSLambdaJavaWithQuarkus/blob/main/quarkus-3.18/src/main/java/software/amazonaws/example/product/handler/AmazonAPIGatewayPrimingResource.javal)

as I only do the same as above:

final APIGatewayProxyRequestEvent proxyRequestEvent = new APIGatewayProxyRequestEvent ();
proxyRequestEvent.setHttpMethod("GET");
proxyRequestEvent.setPathParameters(Map.of("id","0"));

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start with com.amazonaws.serverless.proxy.model.AwsProxyRequest and the validation in AwsProxyHttpServletRequestReader.readRequest. Compare the minimal GET and POST priming examples in the issue with the current request model and context handling. Done means callers can construct the shown requests without dummy fields or objects while valid API Gateway requests continue to work.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
aws, java, spring-boot
Área
api, backend
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.