1+ package com .amazonaws .services .lambda .runtime .events ;
2+
3+ import lombok .AllArgsConstructor ;
4+ import lombok .Builder ;
5+ import lombok .Data ;
6+ import lombok .NoArgsConstructor ;
7+
8+ import java .util .Map ;
9+
10+ /**
11+ * Event to allow transformations to occur before an S3 object is returned to the calling service.
12+ *
13+ * <strong>Documentation</strong>
14+ *
15+ * <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/olap-writing-lambda.html">Writing and debugging Lambda functions for S3 Object Lambda Access Points</a>
16+ *
17+ * <strong>Example:</strong>
18+ *
19+ * <pre>
20+ * <code>import com.amazonaws.services.lambda.runtime.Context;
21+ * import com.amazonaws.services.lambda.runtime.events.S3ObjectLambdaEvent;
22+ * import org.apache.http.client.fluent.Request;
23+ * import software.amazon.awssdk.services.s3.S3Client;
24+ * import software.amazon.awssdk.services.s3.model.WriteGetObjectResponseRequest;
25+ *
26+ * import java.io.IOException;
27+ *
28+ * import static software.amazon.awssdk.core.sync.RequestBody.fromString;
29+ *
30+ * public class S3ObjectRequestHandler {
31+ *
32+ * private static final S3Client s3Client = S3Client.create();
33+ *
34+ * public void handleRequest(S3ObjectLambdaEvent event, Context context) throws IOException {
35+ * String s3Body = Request.Get(event.inputS3Url()).execute().returnContent().asString();
36+ *
37+ * String responseBody = s3Body.toUpperCase();
38+ *
39+ * WriteGetObjectResponseRequest request = WriteGetObjectResponseRequest.builder()
40+ * .requestRoute(event.outputRoute())
41+ * .requestToken(event.outputToken())
42+ * .build();
43+ * s3Client.writeGetObjectResponse(request, fromString(responseBody));
44+ * }
45+ * }
46+ * </code>
47+ * </pre>
48+ */
49+
50+ @ Data
51+ @ Builder (setterPrefix = "with" )
52+ @ NoArgsConstructor
53+ @ AllArgsConstructor
54+ public class S3ObjectLambdaEvent {
55+
56+ private String xAmzRequestId ;
57+ private GetObjectContext getObjectContext ;
58+ private Configuration configuration ;
59+ private UserRequest userRequest ;
60+ private UserIdentity userIdentity ;
61+ private String protocolVersion ;
62+
63+ /**
64+ * A pre-signed URL that can be used to fetch the original object from Amazon S3.
65+ *
66+ * The URL is signed using the original caller’s identity, and their permissions
67+ * will apply when the URL is used. If there are signed headers in the URL, the
68+ * Lambda function must include these in the call to Amazon S3, except for the Host.
69+ *
70+ * @return A pre-signed URL that can be used to fetch the original object from Amazon S3.
71+ */
72+ public String inputS3Url () {
73+ return getGetObjectContext ().getInputS3Url ();
74+ }
75+
76+ /**
77+ * A routing token that is added to the S3 Object Lambda URL when the Lambda function
78+ * calls the S3 API WriteGetObjectResponse.
79+ *
80+ * @return the outputRoute
81+ */
82+ public String outputRoute () {
83+ return getGetObjectContext ().getOutputRoute ();
84+ }
85+
86+ /**
87+ * An opaque token used by S3 Object Lambda to match the WriteGetObjectResponse call
88+ * with the original caller.
89+ *
90+ * @return the outputToken
91+ */
92+ public String outputToken () {
93+ return getGetObjectContext ().getOutputToken ();
94+ }
95+
96+ @ Data
97+ @ Builder (setterPrefix = "with" )
98+ @ NoArgsConstructor
99+ @ AllArgsConstructor
100+ public static class GetObjectContext {
101+ private String inputS3Url ;
102+ private String outputRoute ;
103+ private String outputToken ;
104+ }
105+
106+ @ Data
107+ @ Builder (setterPrefix = "with" )
108+ @ NoArgsConstructor
109+ @ AllArgsConstructor
110+ public static class Configuration {
111+ private String accessPointArn ;
112+ private String supportingAccessPointArn ;
113+ private String payload ;
114+ }
115+
116+ @ Data
117+ @ Builder (setterPrefix = "with" )
118+ @ NoArgsConstructor
119+ @ AllArgsConstructor
120+ public static class UserRequest {
121+ private String url ;
122+ private Map <String , String > headers ;
123+ }
124+
125+ @ Data
126+ @ Builder (setterPrefix = "with" )
127+ @ NoArgsConstructor
128+ @ AllArgsConstructor
129+ public static class UserIdentity {
130+ private String type ;
131+ private String principalId ;
132+ private String arn ;
133+ private String accountId ;
134+ private String accessKeyId ;
135+ }
136+ }
0 commit comments