Skip to content

Additional HTTP event and response objects. #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <a href="https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html">Invoking Lambda function URLs</a>
*/
@AllArgsConstructor
@Builder(setterPrefix = "with")
@Data
@NoArgsConstructor
public class LambdaFunctionURLRequest {
private String version;
private String rawPath;
private String rawQueryString;
private List<String> cookies;
private Map<String, String> headers;
private Map<String, String> 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<String, Object> lambda;
private APIGatewayV2HTTPEvent.RequestContext.IAM iam;

@AllArgsConstructor
@Builder(setterPrefix = "with")
@Data
@NoArgsConstructor
public static class JWT {
private Map<String, String> claims;
private List<String> 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html">Invoking Lambda function URLs</a>
*/
@AllArgsConstructor
@Builder(setterPrefix = "with")
@Data
@NoArgsConstructor
public class LambdaFunctionURLResponse {
private int statusCode;
private Map<String, String> headers;
private List<String> cookies;
private String body;
private boolean isBase64Encoded;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Arguments> 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),
Expand All @@ -36,6 +37,7 @@ private static Stream<Arguments> 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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": "2.0",
"rawPath": "/my/path",
"rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value",
"cookies": [
"cookie1",
"cookie2"
],
"headers": {
"header1": "value1",
"header2": "value1,value2"
},
"queryStringParameters": {
"parameter1": "value1,value2",
"parameter2": "value"
},
"requestContext": {
"accountId": "123456789012",
"apiId": "<urlid>",
"authorizer": {
"iam": {
"accessKey": "AKIA...",
"accountId": "111122223333",
"callerId": "AIDA...",
"userArn": "arn:aws:iam::111122223333:user/example-user",
"userId": "AIDA..."
}
},
"domainName": "<url-id>.lambda-url.us-west-2.on.aws",
"domainPrefix": "<url-id>",
"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
}
Original file line number Diff line number Diff line change
@@ -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
}