aws / aws/serverless-java-container

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

Đang mở
#1,495 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
1.6k
Fork
574
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với com.amazonaws.serverless.proxy.model.AwsProxyRequest và phần xác thực trong AwsProxyHttpServletRequestReader.readRequest. So sánh các ví dụ tối thiểu để khởi tạo GET và POST trong issue với request model hiện tại và cách xử lý context. Hoàn tất khi caller có thể tạo các request được minh họa mà không cần các field hoặc object giả, đồng thời các API Gateway request hợp lệ vẫn tiếp tục hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
aws, java, spring-boot
Lĩnh vực
api, backend
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.