Skip to content

Commit ec207b8

Browse files
authored
Merge pull request awsdocs#422 from awsdocs/use-java-11
Use java 11. (blank-java, java-basic, java-events)
2 parents afd6c19 + 95ff514 commit ec207b8

Some content is hidden

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

47 files changed

+639
-391
lines changed

sample-apps/blank-java/build.gradle

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,16 @@ repositories {
77
}
88

99
dependencies {
10-
implementation platform('software.amazon.awssdk:bom:2.10.73')
10+
implementation platform('software.amazon.awssdk:bom:2.10.72')
1111
implementation platform('com.amazonaws:aws-xray-recorder-sdk-bom:2.4.0')
1212
implementation 'software.amazon.awssdk:lambda'
1313
implementation 'com.amazonaws:aws-xray-recorder-sdk-core'
14-
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-core'
15-
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2'
16-
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2-instrumentor'
1714
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
1815
implementation 'com.amazonaws:aws-lambda-java-events:2.2.9'
19-
implementation 'org.apache.logging.log4j:log4j-api:[2.17.1,)'
20-
implementation 'org.apache.logging.log4j:log4j-core:[2.17.1,)'
21-
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:[2.17.1,)'
22-
runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.5.0'
16+
implementation 'org.slf4j:slf4j-nop:2.0.6'
2317
testImplementation 'com.amazonaws:aws-lambda-java-tests:1.1.1'
24-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
25-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
18+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
19+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
2620
}
2721

2822
test {
@@ -53,8 +47,8 @@ task packageSkinny(type: Zip) {
5347
}
5448

5549
java {
56-
sourceCompatibility = JavaVersion.VERSION_1_8
57-
targetCompatibility = JavaVersion.VERSION_1_8
50+
sourceCompatibility = JavaVersion.VERSION_11
51+
targetCompatibility = JavaVersion.VERSION_11
5852
}
5953

6054
build.dependsOn packageSkinny

sample-apps/blank-java/pom.xml

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<name>blank-java-function</name>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11-
<maven.compiler.source>1.8</maven.compiler.source>
12-
<maven.compiler.target>1.8</maven.compiler.target>
11+
<maven.compiler.source>11</maven.compiler.source>
12+
<maven.compiler.target>11</maven.compiler.target>
1313
</properties>
1414
<dependencies>
1515
<dependency>
@@ -23,24 +23,9 @@
2323
<version>2.2.9</version>
2424
</dependency>
2525
<dependency>
26-
<groupId>com.amazonaws</groupId>
27-
<artifactId>aws-lambda-java-log4j2</artifactId>
28-
<version>1.5.0</version>
29-
</dependency>
30-
<dependency>
31-
<groupId>org.apache.logging.log4j</groupId>
32-
<artifactId>log4j-api</artifactId>
33-
<version>[2.17.1,)</version>
34-
</dependency>
35-
<dependency>
36-
<groupId>org.apache.logging.log4j</groupId>
37-
<artifactId>log4j-core</artifactId>
38-
<version>[2.17.1,)</version>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.apache.logging.log4j</groupId>
42-
<artifactId>log4j-slf4j18-impl</artifactId>
43-
<version>[2.17.1,)</version>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-nop</artifactId>
28+
<version>2.0.6</version>
4429
</dependency>
4530
<dependency>
4631
<groupId>software.amazon.awssdk</groupId>
@@ -52,31 +37,16 @@
5237
<artifactId>aws-xray-recorder-sdk-core</artifactId>
5338
<version>2.4.0</version>
5439
</dependency>
55-
<dependency>
56-
<groupId>com.amazonaws</groupId>
57-
<artifactId>aws-xray-recorder-sdk-aws-sdk-core</artifactId>
58-
<version>2.4.0</version>
59-
</dependency>
60-
<dependency>
61-
<groupId>com.amazonaws</groupId>
62-
<artifactId>aws-xray-recorder-sdk-aws-sdk-v2</artifactId>
63-
<version>2.4.0</version>
64-
</dependency>
65-
<dependency>
66-
<groupId>com.amazonaws</groupId>
67-
<artifactId>aws-xray-recorder-sdk-aws-sdk-v2-instrumentor</artifactId>
68-
<version>2.4.0</version>
69-
</dependency>
7040
<dependency>
7141
<groupId>org.junit.jupiter</groupId>
7242
<artifactId>junit-jupiter-api</artifactId>
73-
<version>5.6.0</version>
43+
<version>5.8.2</version>
7444
<scope>test</scope>
7545
</dependency>
7646
<dependency>
7747
<groupId>org.junit.jupiter</groupId>
7848
<artifactId>junit-jupiter-engine</artifactId>
79-
<version>5.6.0</version>
49+
<version>5.8.2</version>
8050
<scope>test</scope>
8151
</dependency>
8252
<dependency>
@@ -99,36 +69,34 @@
9969
<version>3.2.2</version>
10070
<configuration>
10171
<createDependencyReducedPom>false</createDependencyReducedPom>
72+
<filters>
73+
<filter>
74+
<artifact>*:*</artifact>
75+
<excludes>
76+
<exclude>module-info.class</exclude>
77+
<exclude>META-INF/*</exclude>
78+
<exclude>META-INF/versions/**</exclude>
79+
<exclude>META-INF/services/**</exclude>
80+
</excludes>
81+
</filter>
82+
</filters>
10283
</configuration>
10384
<executions>
10485
<execution>
10586
<phase>package</phase>
10687
<goals>
10788
<goal>shade</goal>
10889
</goals>
109-
<configuration>
110-
<transformers>
111-
<transformer implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer">
112-
</transformer>
113-
</transformers>
114-
</configuration>
11590
</execution>
11691
</executions>
117-
<dependencies>
118-
<dependency>
119-
<groupId>com.github.edwgiz</groupId>
120-
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
121-
<version>[2.17.1,)</version>
122-
</dependency>
123-
</dependencies>
12492
</plugin>
12593
<plugin>
12694
<groupId>org.apache.maven.plugins</groupId>
12795
<artifactId>maven-compiler-plugin</artifactId>
12896
<version>3.8.1</version>
12997
<configuration>
130-
<source>1.8</source>
131-
<target>1.8</target>
98+
<source>11</source>
99+
<target>11</target>
132100
</configuration>
133101
</plugin>
134102
</plugins>

sample-apps/blank-java/src/main/java/example/Handler.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
package example;
22

33
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.LambdaLogger;
45
import com.amazonaws.services.lambda.runtime.RequestHandler;
56

67
import java.util.Map;
78

8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
10-
119
import software.amazon.awssdk.services.lambda.LambdaClient;
1210
import software.amazon.awssdk.services.lambda.model.GetAccountSettingsResponse;
1311
import software.amazon.awssdk.services.lambda.model.LambdaException;
1412

1513
// Handler value: example.Handler
1614
public class Handler implements RequestHandler<Map<String,String>, String> {
1715

18-
private static final Logger logger = LoggerFactory.getLogger(Handler.class);
1916
private static final LambdaClient lambdaClient = LambdaClient.builder().build();
2017

2118
@Override
2219
public String handleRequest(Map<String,String> event, Context context) {
2320

24-
logger.info("ENVIRONMENT VARIABLES: " + System.getenv());
25-
logger.info("EVENT: " + event);
21+
LambdaLogger logger = context.getLogger();
22+
logger.log("Handler invoked");
2623

2724
GetAccountSettingsResponse response = null;
2825
try {
2926
response = lambdaClient.getAccountSettings();
3027
} catch(LambdaException e) {
31-
System.err.println(e.getMessage());
28+
logger.log(e.getMessage());
3229
}
3330
return response != null ? "Total code size for your account is " + response.accountLimit().totalCodeSize() + " bytes" : "Error";
3431
}

sample-apps/blank-java/src/main/resources/log4j2.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

sample-apps/blank-java/template-mvn.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Resources:
77
Properties:
88
CodeUri: target/blank-java-1.0-SNAPSHOT.jar
99
Handler: example.Handler::handleRequest
10-
Runtime: java8
10+
Runtime: java11
1111
Description: Java function
12-
MemorySize: 512
12+
MemorySize: 2048
1313
Timeout: 10
1414
# Function's execution role
1515
Policies:
@@ -18,3 +18,13 @@ Resources:
1818
- AWSXrayWriteOnlyAccess
1919
- AWSLambdaVPCAccessExecutionRole
2020
Tracing: Active
21+
Layers:
22+
- !Ref libs
23+
libs:
24+
Type: AWS::Serverless::LayerVersion
25+
Properties:
26+
LayerName: blank-java-lib
27+
Description: Dependencies for the blank-java sample app.
28+
ContentUri: build/blank-java-lib.zip
29+
CompatibleRuntimes:
30+
- java11

sample-apps/blank-java/template.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Resources:
77
Properties:
88
CodeUri: build/distributions/blank-java.zip
99
Handler: example.Handler::handleRequest
10-
Runtime: java8
10+
Runtime: java11
1111
Description: Java function
12-
MemorySize: 512
12+
MemorySize: 2048
1313
Timeout: 10
1414
# Function's execution role
1515
Policies:
@@ -27,4 +27,4 @@ Resources:
2727
Description: Dependencies for the blank-java sample app.
2828
ContentUri: build/blank-java-lib.zip
2929
CompatibleRuntimes:
30-
- java8
30+
- java11

sample-apps/java-basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ To use a different handler, change the value of the Handler setting in the appli
9595
CodeUri: build/distributions/java-basic.zip
9696
Handler: example.HandlerList
9797

98-
Deploy the change, and then use the invoke script to test the new configuration. For handlers, that don't take a JSON object as input, pass the type (`string`, `int` or `list`) as an argument to the invoke script.
98+
Deploy the change, and then use the invoke script to test the new configuration. For handlers, that don't take a JSON object as input, pass the type (`string`, `int`, `list`, or `divide`) as an argument to the invoke script.
9999

100100
./3-invoke.sh list
101101
{

sample-apps/java-basic/build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ repositories {
88

99
dependencies {
1010
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
11-
testImplementation 'org.apache.logging.log4j:log4j-api:[2.17.1,)'
12-
testImplementation 'org.apache.logging.log4j:log4j-core:[2.17.1,)'
13-
testImplementation 'org.apache.logging.log4j:log4j-slf4j18-impl:[2.17.1,)'
14-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
15-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
11+
implementation 'org.slf4j:slf4j-nop:2.0.6'
12+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
13+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
1614
}
1715

1816
test {
@@ -28,8 +26,8 @@ task buildZip(type: Zip) {
2826
}
2927

3028
java {
31-
sourceCompatibility = JavaVersion.VERSION_1_8
32-
targetCompatibility = JavaVersion.VERSION_1_8
29+
sourceCompatibility = JavaVersion.VERSION_11
30+
targetCompatibility = JavaVersion.VERSION_11
3331
}
3432

3533
build.dependsOn buildZip

sample-apps/java-basic/pom.xml

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<name>java-basic-function</name>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11-
<maven.compiler.source>1.8</maven.compiler.source>
12-
<maven.compiler.target>1.8</maven.compiler.target>
11+
<maven.compiler.source>11</maven.compiler.source>
12+
<maven.compiler.target>11</maven.compiler.target>
1313
</properties>
1414
<dependencies>
1515
<dependency>
@@ -18,35 +18,22 @@
1818
<version>1.2.1</version>
1919
</dependency>
2020
<dependency>
21-
<groupId>org.apache.logging.log4j</groupId>
22-
<artifactId>log4j-api</artifactId>
23-
<version>[2.17.1,)</version>
24-
<scope>test</scope>
21+
<groupId>org.slf4j</groupId>
22+
<artifactId>slf4j-nop</artifactId>
23+
<version>2.0.6</version>
2524
</dependency>
2625
<dependency>
27-
<groupId>org.apache.logging.log4j</groupId>
28-
<artifactId>log4j-core</artifactId>
29-
<version>[2.17.1,)</version>
30-
<scope>test</scope>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.apache.logging.log4j</groupId>
34-
<artifactId>log4j-slf4j18-impl</artifactId>
35-
<version>[2.17.1,)</version>
36-
<scope>test</scope>
37-
</dependency>
38-
<dependency>
3926
<groupId>org.junit.jupiter</groupId>
4027
<artifactId>junit-jupiter-api</artifactId>
41-
<version>5.6.0</version>
28+
<version>5.8.2</version>
4229
<scope>test</scope>
43-
</dependency>
44-
<dependency>
30+
</dependency>
31+
<dependency>
4532
<groupId>org.junit.jupiter</groupId>
4633
<artifactId>junit-jupiter-engine</artifactId>
47-
<version>5.6.0</version>
34+
<version>5.8.2</version>
4835
<scope>test</scope>
49-
</dependency>
36+
</dependency>
5037
</dependencies>
5138

5239
<build>
@@ -61,6 +48,17 @@
6148
<version>3.2.2</version>
6249
<configuration>
6350
<createDependencyReducedPom>false</createDependencyReducedPom>
51+
<filters>
52+
<filter>
53+
<artifact>*:*</artifact>
54+
<excludes>
55+
<exclude>module-info.class</exclude>
56+
<exclude>META-INF/*</exclude>
57+
<exclude>META-INF/versions/**</exclude>
58+
<exclude>META-INF/services/**</exclude>
59+
</excludes>
60+
</filter>
61+
</filters>
6462
</configuration>
6563
<executions>
6664
<execution>
@@ -76,8 +74,8 @@
7674
<artifactId>maven-compiler-plugin</artifactId>
7775
<version>3.8.1</version>
7876
<configuration>
79-
<source>1.8</source>
80-
<target>1.8</target>
77+
<source>11</source>
78+
<target>11</target>
8179
</configuration>
8280
</plugin>
8381
</plugins>

0 commit comments

Comments
 (0)