diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java index fca77846..4f2308c5 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java @@ -13,6 +13,9 @@ package com.amazonaws.services.lambda.runtime.events; +import com.amazonaws.services.lambda.runtime.events.apigateway.HttpRequestEvent; +import com.amazonaws.services.lambda.runtime.events.apigateway.RequestSource; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -34,7 +37,13 @@ @Builder(setterPrefix = "with") @NoArgsConstructor @AllArgsConstructor -public class ApplicationLoadBalancerRequestEvent implements Serializable { +public class ApplicationLoadBalancerRequestEvent implements Serializable, HttpRequestEvent { + + @Override + @JsonIgnore + public RequestSource getRequestSource() { + return RequestSource.ALB; + } @Data @Builder(setterPrefix = "with") diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/AwsProxyResponseEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/AwsProxyResponseEvent.java new file mode 100644 index 00000000..b8ec7bce --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/AwsProxyResponseEvent.java @@ -0,0 +1,33 @@ +package com.amazonaws.services.lambda.runtime.events; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + Common response class for APIGateway and ALB + */ +@NoArgsConstructor +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AwsProxyResponseEvent { + private static final long serialVersionUID = 2263167344670024138L; + + private Integer statusCode; + + private String statusDescription; + + private List cookies; + + private Map headers; + + private Map> multiValueHeaders; + + private String body; + + private Boolean isBase64Encoded; +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayProxyRequestEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayProxyRequestEvent.java index 0d8f3378..6c2761cc 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayProxyRequestEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayProxyRequestEvent.java @@ -13,6 +13,7 @@ package com.amazonaws.services.lambda.runtime.events.apigateway; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -30,7 +31,7 @@ @Builder(setterPrefix = "with") @NoArgsConstructor @AllArgsConstructor -public class APIGatewayProxyRequestEvent implements Serializable { +public class APIGatewayProxyRequestEvent implements Serializable, HttpRequestEvent { private static final long serialVersionUID = 4189228800688527467L; @@ -47,6 +48,12 @@ public class APIGatewayProxyRequestEvent implements Serializable { private String body; private Boolean isBase64Encoded; + @Override + @JsonIgnore + public RequestSource getRequestSource() { + return RequestSource.API_GATEWAY_REST; + } + /** * class that represents proxy request context */ diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayV2HTTPEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayV2HTTPEvent.java index d2f713ad..4ba5e5a8 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayV2HTTPEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/APIGatewayV2HTTPEvent.java @@ -13,6 +13,7 @@ package com.amazonaws.services.lambda.runtime.events.apigateway; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -30,7 +31,7 @@ @Builder(setterPrefix = "with") @Data @NoArgsConstructor -public class APIGatewayV2HTTPEvent { +public class APIGatewayV2HTTPEvent implements HttpRequestEvent { private String version; private String routeKey; @@ -45,6 +46,12 @@ public class APIGatewayV2HTTPEvent { private boolean isBase64Encoded; private RequestContext requestContext; + @Override + @JsonIgnore + public RequestSource getRequestSource() { + return RequestSource.API_GATEWAY_HTTP; + } + @AllArgsConstructor @Builder(setterPrefix = "with") @Data diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/HttpRequestEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/HttpRequestEvent.java new file mode 100644 index 00000000..280ebd58 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/HttpRequestEvent.java @@ -0,0 +1,8 @@ +package com.amazonaws.services.lambda.runtime.events.apigateway; + +/** + * A common interface shared by event sources which produce HTTP as JSON + */ +public interface HttpRequestEvent { + RequestSource getRequestSource(); +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/RequestSource.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/RequestSource.java new file mode 100644 index 00000000..5c0bd19a --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/apigateway/RequestSource.java @@ -0,0 +1,7 @@ +package com.amazonaws.services.lambda.runtime.events.apigateway; + +public enum RequestSource { + API_GATEWAY_REST, + API_GATEWAY_HTTP, + ALB +}