Skip to content
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

Objects to represent VPC Lattice V2 request and response. #442

Closed
wants to merge 5 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
5 changes: 5 additions & 0 deletions aws-lambda-java-events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>joda-time</artifactId>
<version>2.10.8</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

package com.amazonaws.services.lambda.runtime.events;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public class VpcLatticeResponse {

private boolean isBase64Encoded;
private int statusCode;
private String statusDescription;
private Map<String, String> headers;
private String body;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

package com.amazonaws.services.lambda.runtime.events;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Nullable;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;

/**
* <a href="https://docs.aws.amazon.com/vpc-lattice/latest/ug/lambda-functions.html">Lambda functions as targets in VPC Lattice</a>
*
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public class VpcLatticeV2RequestEvent {

private String version;
private String path;
private String method;
private Map<String, List<String>> headers;
@Nullable
private Map<String, String> queryStringParameters;
private RequestContext requestContext;
private String body;

/***
* isBase64Encoded is set if the body is a base64 encoded String.
*/
@Nullable
private Boolean isBase64Encoded;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class RequestContext {
private String serviceNetworkArn;
private String serviceArn;
private String targetGroupArn;
private Identity identity;
private String region;
/**
* Number of microseconds from the epoch
*/
private String timeEpoch;

public LocalDateTime getLocalDateTime() {
long epochMicroseconds = Long.parseLong(timeEpoch);
long epochMilliseconds = epochMicroseconds / 1000;

return Instant.ofEpochMilli(epochMilliseconds).atZone(ZoneOffset.UTC).toLocalDateTime();
}
}

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class Identity {
private String sourceVpcArn;
private String type;
private String principal;
private String sessionName;
private String x509SanDns;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.amazonaws.services.lambda.runtime.events;

import org.junit.jupiter.api.Test;

import java.time.format.DateTimeFormatter;

import static org.junit.jupiter.api.Assertions.assertEquals;

class VpcLatticeV2RequestEventTest {

@Test
public void epochAsTime() {
VpcLatticeV2RequestEvent.RequestContext requestContext = new VpcLatticeV2RequestEvent.RequestContext().builder()
.withTimeEpoch("1690497599177430")
.build();

assertEquals("2023-07-27T22:39:59.177", requestContext.getLocalDateTime().format(DateTimeFormatter.ISO_DATE_TIME));
}
}