Skip to content

Commit 4d85b6c

Browse files
committed
initial checkin
1 parent ea8777d commit 4d85b6c

File tree

87 files changed

+7898
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+7898
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# Mobile Tools for Java (J2ME)
1111
.mtj.tmp/
12+
.idea/
13+
target/
1214

1315
# Package Files #
1416
*.jar

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
1-
# light-lambda-native
2-
A Lambda native gateway with cross-cutting concerns implemented in Java
1+
### Test with Main
2+
3+
We have provided a Main class in the src folder for testing all the middleware handlers with a sample request. You can run the Main class within your IDE with debug mode to see how each middleware handler works.
4+
5+
Before running the Main class, you need to disable the DynamoDbCacheManager as it depends on the AWS environment. To do that you need to common out the service.yml section in the values.yml
6+
7+
```
8+
# ------------< Service Config >-------------
9+
service.singletons:
10+
# - com.networknt.cache.CacheManager:
11+
# - com.networknt.aws.lambda.cache.DynamoDbCacheManager
12+
# -------------------------------------------
13+
```
14+
15+
If you want to enable the JWT verification, you need to make sure the token use in the Main class is matching the jwk configuration in the values.yml
16+
17+
```
18+
# client.yml
19+
client.tokenKeyServerUrl: https://networknt.oktapreview.com
20+
client.tokenKeyUri: /oauth2/aus66u5cybTrCsbZs1d6/v1/keys
21+
```
22+
23+
If everything works fine, you should see the following error that indicate all middleware handlers are passed and the AWS Lambda invocation is failed. This is because we are testing without AWS environment.
24+
25+
```
26+
22:38:36.103 [main] DEBUG software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain -- Unable to load credentials from SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).
27+
software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).
28+
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:111)
29+
at software.amazon.awssdk.auth.credentials.internal.SystemSettingsCredentialsProvider.resolveCredentials(SystemSettingsCredentialsProvider.java:58)
30+
at software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain.resolveCredentials(AwsCredentialsProviderChain.java:96)
31+
at software.amazon.awssdk.auth.credentials.internal.LazyAwsCredentialsProvider.resolveCredentials(LazyAwsCredentialsProvider.java:45)
32+
at software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider.resolveCredentials(DefaultCredentialsProvider.java:126)
33+
at software.amazon.awssdk.core.internal.util.MetricUtils.measureDuration(MetricUtils.java:50)
34+
at software.amazon.awssdk.awscore.internal.authcontext.AwsCredentialsAuthorizationStrategy.resolveCredentials(AwsCredentialsAuthorizationStrategy.java:100)
35+
at software.amazon.awssdk.awscore.internal.authcontext.AwsCredentialsAuthorizationStrategy.addCredentialsToExecutionAttributes(AwsCredentialsAuthorizationStrategy.java:77)
36+
at software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder.invokeInterceptorsAndCreateExecutionContext(AwsExecutionContextBuilder.java:123)
37+
at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.invokeInterceptorsAndCreateExecutionContext(AwsSyncClientHandler.java:69)
38+
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.lambda$execute$1(BaseSyncClientHandler.java:78)
39+
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.measureApiCallSuccess(BaseSyncClientHandler.java:179)
40+
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:76)
41+
at software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:45)
42+
at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:56)
43+
at software.amazon.awssdk.services.lambda.DefaultLambdaClient.invoke(DefaultLambdaClient.java:2694)
44+
at com.networknt.aws.lambda.proxy.LambdaProxy.invokeFunction(LambdaProxy.java:132)
45+
at com.networknt.aws.lambda.proxy.LambdaProxy.handleRequest(LambdaProxy.java:94)
46+
at com.networknt.aws.lambda.Main.main(Main.java:157)
47+
```

bootstrap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
./LambdaProxy

native-image-linux.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PROJECT_NAME=CccLambda
2+
PROJECT_VERSION=1.0.0
3+
4+
# mvn clean might fail due to permission issue on Linux, so remove target with root.
5+
sudo rm -rf target;
6+
# Generate Jar file
7+
mvn clean install;
8+
9+
# Generate Native Image
10+
docker run --rm --name graal -v $(pwd):/${PROJECT_NAME} springci/graalvm-ce:master-java11 \
11+
/bin/bash -c "native-image \
12+
-H:EnableURLProtocols=http \
13+
--no-fallback \
14+
--allow-incomplete-classpath \
15+
--enable-all-security-services \
16+
-H:ReflectionConfigurationFiles=/${PROJECT_NAME}/reflect.json \
17+
-H:ResourceConfigurationFiles=/${PROJECT_NAME}/resource-config.json \
18+
-H:+ReportExceptionStackTraces \
19+
-jar /${PROJECT_NAME}/target/${PROJECT_NAME}-${PROJECT_VERSION}.jar \
20+
; \
21+
mkdir /${PROJECT_NAME}/target/custom-runtime \
22+
; \
23+
cp ${PROJECT_NAME}-${PROJECT_VERSION} /${PROJECT_NAME}/target/custom-runtime/${PROJECT_NAME}";
24+
25+
# Copy the bootstrap to the custom-runtime
26+
sudo cp bootstrap target/custom-runtime/bootstrap;
27+
28+
# Make bootstrap executable
29+
sudo chmod +x target/custom-runtime/bootstrap;
30+
31+
# Zip
32+
rm $PROJECT_NAME-custom-runtime.zip
33+
cd target/custom-runtime || exit
34+
zip -X -r ../../$PROJECT_NAME-custom-runtime.zip .

0 commit comments

Comments
 (0)