This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
/
ApiLambdaHandler.java
66 lines (57 loc) · 2.91 KB
/
ApiLambdaHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package software.amazon.serverless.apprepo.container;
import com.amazonaws.serverless.proxy.jersey.JerseyLambdaContainerHandler;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.inject.Singleton;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.kms.KmsClient;
import software.amazon.serverless.apprepo.api.exception.ApiExceptionMapper;
import software.amazon.serverless.apprepo.api.impl.ApplicationsService;
import software.amazon.serverless.apprepo.api.impl.pagination.PaginationTokenSerializer;
import software.amazon.serverless.apprepo.api.impl.pagination.TokenSerializer;
import software.amazon.serverless.apprepo.container.config.ConfigProvider;
import software.amazon.serverless.apprepo.container.factory.DynamoDbClientFactory;
import software.amazon.serverless.apprepo.container.factory.KmsClientFactory;
import software.amazon.serverless.apprepo.container.factory.SsmConfigProviderFactory;
/**
* API Lambda handler. This is the entry point for the API Lambda.
*/
public class ApiLambdaHandler implements RequestStreamHandler {
private static final ResourceConfig jerseyApplication = new ResourceConfig()
.registerClasses(ApplicationsService.class, ApiExceptionMapper.class,
CorsHeadersResponseFilter.class)
.register(JacksonFeature.class)
.register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(DynamoDbClientFactory.class)
.to(DynamoDbClient.class).in(Singleton.class);
bindFactory(SsmConfigProviderFactory.class)
.to(ConfigProvider.class).in(Singleton.class);
bindFactory(KmsClientFactory.class)
.to(KmsClient.class).in(Singleton.class);
bind(PaginationTokenSerializer.class)
.to(new TypeLiteral<TokenSerializer<Map<String, AttributeValue>>>() {
})
.in(Singleton.class);
}
});
private static final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler
= JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}