aws / aws/serverless-java-container

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

Ouverte
#1,495 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
1.6k
Forks
574
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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"));

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
aws, java, spring-boot
Domaine
api, backend
Type d'issue
Fonctionnalité
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.