diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaFunctionURLRequest.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaFunctionURLRequest.java new file mode 100644 index 00000000..647d4ec0 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaFunctionURLRequest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * Class to represent a Lambda function HTTP Request. + * + * @see Invoking Lambda function URLs + */ +@AllArgsConstructor +@Builder(setterPrefix = "with") +@Data +@NoArgsConstructor +public class LambdaFunctionURLRequest { + private String version; + private String rawPath; + private String rawQueryString; + private List cookies; + private Map headers; + private Map queryStringParameters; + private String body; + private boolean isBase64Encoded; + private APIGatewayV2HTTPEvent.RequestContext requestContext; + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class RequestContext { + private String accountId; + private String apiId; + private String domainName; + private String domainPrefix; + private String time; + private long timeEpoch; + private APIGatewayV2HTTPEvent.RequestContext.Http http; + private APIGatewayV2HTTPEvent.RequestContext.Authorizer authorizer; + private String requestId; + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class Authorizer { + private APIGatewayV2HTTPEvent.RequestContext.Authorizer.JWT jwt; + private Map lambda; + private APIGatewayV2HTTPEvent.RequestContext.IAM iam; + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class JWT { + private Map claims; + private List scopes; + } + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class Http { + private String method; + private String path; + private String protocol; + private String sourceIp; + private String userAgent; + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class IAM { + private String accessKey; + private String accountId; + private String callerId; + private String userArn; + private String userId; + } + } +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaFunctionURLResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaFunctionURLResponse.java new file mode 100644 index 00000000..87a15559 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaFunctionURLResponse.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * Class to represent a Lambda function HTTP Response. + * + * @see Invoking Lambda function URLs + */ +@AllArgsConstructor +@Builder(setterPrefix = "with") +@Data +@NoArgsConstructor +public class LambdaFunctionURLResponse { + private int statusCode; + private Map headers; + private List cookies; + private String body; + private boolean isBase64Encoded; +} diff --git a/aws-lambda-java-serialization/src/test/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializersTest.java b/aws-lambda-java-serialization/src/test/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializersTest.java index c1d9fd0b..8cbb1e9a 100644 --- a/aws-lambda-java-serialization/src/test/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializersTest.java +++ b/aws-lambda-java-serialization/src/test/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializersTest.java @@ -4,8 +4,8 @@ import com.amazonaws.services.lambda.runtime.events.*; import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer; +import com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -22,11 +22,12 @@ public class LambdaEventSerializersTest { - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); public static final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader(); + public static final ObjectMapper OBJECT_MAPPER = JacksonFactory.getInstance().getMapper(); private static Stream serdeArguments() { return Stream.of( + Arguments.of("lambda_function_url_request.json", LambdaFunctionURLRequest.class), Arguments.of("api_gateway_proxy_request_event.json", APIGatewayProxyRequestEvent.class), Arguments.of("api_gateway_proxy_response_event.json", APIGatewayProxyResponseEvent.class), Arguments.of("cloud_front_event.json", CloudFrontEvent.class), @@ -36,6 +37,7 @@ private static Stream serdeArguments() { Arguments.of("cognito_event.json", CognitoEvent.class), Arguments.of("config_event.json", ConfigEvent.class), Arguments.of("dynamodb_event.json", DynamodbEvent.class), + Arguments.of("lambda_function_url_response.json", LambdaFunctionURLResponse.class), Arguments.of("iot_button_event.json", IoTButtonEvent.class), Arguments.of("kinesis_analytics_firehose_input_preprocessing_event.json", KinesisAnalyticsFirehoseInputPreprocessingEvent.class), Arguments.of("kinesis_analytics_input_preprocessing_response_event.json", KinesisAnalyticsInputPreprocessingResponse.class), diff --git a/aws-lambda-java-serialization/src/test/resources/event_models/lambda_function_url_request.json b/aws-lambda-java-serialization/src/test/resources/event_models/lambda_function_url_request.json new file mode 100644 index 00000000..5d67581f --- /dev/null +++ b/aws-lambda-java-serialization/src/test/resources/event_models/lambda_function_url_request.json @@ -0,0 +1,44 @@ +{ + "version": "2.0", + "rawPath": "/my/path", + "rawQueryString": "parameter1=value1¶meter1=value2¶meter2=value", + "cookies": [ + "cookie1", + "cookie2" + ], + "headers": { + "header1": "value1", + "header2": "value1,value2" + }, + "queryStringParameters": { + "parameter1": "value1,value2", + "parameter2": "value" + }, + "requestContext": { + "accountId": "123456789012", + "apiId": "", + "authorizer": { + "iam": { + "accessKey": "AKIA...", + "accountId": "111122223333", + "callerId": "AIDA...", + "userArn": "arn:aws:iam::111122223333:user/example-user", + "userId": "AIDA..." + } + }, + "domainName": ".lambda-url.us-west-2.on.aws", + "domainPrefix": "", + "http": { + "method": "POST", + "path": "/my/path", + "protocol": "HTTP/1.1", + "sourceIp": "123.123.123.123", + "userAgent": "agent" + }, + "requestId": "id", + "time": "12/Mar/2020:19:03:58 +0000", + "timeEpoch": 1583348638390 + }, + "body": "Hello from client!", + "isBase64Encoded": false +} \ No newline at end of file diff --git a/aws-lambda-java-serialization/src/test/resources/event_models/lambda_function_url_response.json b/aws-lambda-java-serialization/src/test/resources/event_models/lambda_function_url_response.json new file mode 100644 index 00000000..74f78b8b --- /dev/null +++ b/aws-lambda-java-serialization/src/test/resources/event_models/lambda_function_url_response.json @@ -0,0 +1,13 @@ +{ + "statusCode": 201, + "headers": { + "Content-Type": "application/json", + "My-Custom-Header": "Custom Value" + }, + "body": "{ \"message\": \"Hello, world!\" }", + "cookies": [ + "Cookie_1=Value1; Expires=21 Oct 2021 07:48 GMT", + "Cookie_2=Value2; Max-Age=78000" + ], + "isBase64Encoded": false +} \ No newline at end of file