Skip to content
Merged
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
18 changes: 6 additions & 12 deletions sample-apps/blank-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@ repositories {
}

dependencies {
implementation platform('software.amazon.awssdk:bom:2.10.73')
implementation platform('software.amazon.awssdk:bom:2.10.72')
implementation platform('com.amazonaws:aws-xray-recorder-sdk-bom:2.4.0')
implementation 'software.amazon.awssdk:lambda'
implementation 'com.amazonaws:aws-xray-recorder-sdk-core'
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-core'
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2'
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2-instrumentor'
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:2.2.9'
implementation 'org.apache.logging.log4j:log4j-api:[2.17.1,)'
implementation 'org.apache.logging.log4j:log4j-core:[2.17.1,)'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:[2.17.1,)'
runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.5.0'
implementation 'org.slf4j:slf4j-nop:2.0.6'
testImplementation 'com.amazonaws:aws-lambda-java-tests:1.1.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

test {
Expand Down Expand Up @@ -53,8 +47,8 @@ task packageSkinny(type: Zip) {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

build.dependsOn packageSkinny
72 changes: 20 additions & 52 deletions sample-apps/blank-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<name>blank-java-function</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
Expand All @@ -23,24 +23,9 @@
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j2</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.17.1,)</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>[2.17.1,)</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>[2.17.1,)</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency silently discards log messages. I don't think it's a good idea to use it for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually want to remove SLF4J from the dependencies and just use the context logger (SLF4J is required for the testing to work, so I include it for test context only). However, I can't do so because I think another AWS dependency that is pulling in SLF4J somewhere, causing this warning in logs (https://stackoverflow.com/questions/7421612/slf4j-failed-to-load-class-org-slf4j-impl-staticloggerbinder). The warning is resolved with this dependency. That being said, it's just a warning but I wanted all the output and logs to look as clean as possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to include a real implementation of slf4j backend. sl4j-simple for example.

<version>2.0.6</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
Expand All @@ -52,31 +37,16 @@
<artifactId>aws-xray-recorder-sdk-core</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-aws-sdk-core</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-aws-sdk-v2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-aws-sdk-v2-instrumentor</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -99,36 +69,34 @@
<version>3.2.2</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*</exclude>
<exclude>META-INF/versions/**</exclude>
<exclude>META-INF/services/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.github.edwgiz</groupId>
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
<version>[2.17.1,)</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
11 changes: 4 additions & 7 deletions sample-apps/blank-java/src/main/java/example/Handler.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package example;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestHandler;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.amazon.awssdk.services.lambda.LambdaClient;
import software.amazon.awssdk.services.lambda.model.GetAccountSettingsResponse;
import software.amazon.awssdk.services.lambda.model.LambdaException;

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

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

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

logger.info("ENVIRONMENT VARIABLES: " + System.getenv());
logger.info("EVENT: " + event);
LambdaLogger logger = context.getLogger();
logger.log("Handler invoked");

GetAccountSettingsResponse response = null;
try {
response = lambdaClient.getAccountSettings();
} catch(LambdaException e) {
System.err.println(e.getMessage());
logger.log(e.getMessage());
}
return response != null ? "Total code size for your account is " + response.accountLimit().totalCodeSize() + " bytes" : "Error";
}
Expand Down
16 changes: 0 additions & 16 deletions sample-apps/blank-java/src/main/resources/log4j2.xml

This file was deleted.

14 changes: 12 additions & 2 deletions sample-apps/blank-java/template-mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Resources:
Properties:
CodeUri: target/blank-java-1.0-SNAPSHOT.jar
Handler: example.Handler::handleRequest
Runtime: java8
Runtime: java11
Description: Java function
MemorySize: 512
MemorySize: 2048
Timeout: 10
# Function's execution role
Policies:
Expand All @@ -18,3 +18,13 @@ Resources:
- AWSXrayWriteOnlyAccess
- AWSLambdaVPCAccessExecutionRole
Tracing: Active
Layers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't make examples of Lambda functions using Layers for application dependencies

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to provide one example of this, and I think blank-java is a good candidate for it. Some of the other languages in this repo show this pattern as well (Node, Python).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you provide an example of this, it absolutely should be in a separate example. This is not what I would expect from 'blank'. I would call it 'app-dependency-layer' or something similar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank does not mean "empty". You can get an empty function from the management console. It's a sample for demonstrating and testing service features. Layers is an important feature, no?

- !Ref libs
libs:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: blank-java-lib
Description: Dependencies for the blank-java sample app.
ContentUri: build/blank-java-lib.zip
CompatibleRuntimes:
- java11
6 changes: 3 additions & 3 deletions sample-apps/blank-java/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Resources:
Properties:
CodeUri: build/distributions/blank-java.zip
Handler: example.Handler::handleRequest
Runtime: java8
Runtime: java11
Description: Java function
MemorySize: 512
MemorySize: 2048
Timeout: 10
# Function's execution role
Policies:
Expand All @@ -27,4 +27,4 @@ Resources:
Description: Dependencies for the blank-java sample app.
ContentUri: build/blank-java-lib.zip
CompatibleRuntimes:
- java8
- java11
2 changes: 1 addition & 1 deletion sample-apps/java-basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ To use a different handler, change the value of the Handler setting in the appli
CodeUri: build/distributions/java-basic.zip
Handler: example.HandlerList

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.
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.

./3-invoke.sh list
{
Expand Down
12 changes: 5 additions & 7 deletions sample-apps/java-basic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ repositories {

dependencies {
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
testImplementation 'org.apache.logging.log4j:log4j-api:[2.17.1,)'
testImplementation 'org.apache.logging.log4j:log4j-core:[2.17.1,)'
testImplementation 'org.apache.logging.log4j:log4j-slf4j18-impl:[2.17.1,)'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
implementation 'org.slf4j:slf4j-nop:2.0.6'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

test {
Expand All @@ -28,8 +26,8 @@ task buildZip(type: Zip) {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

build.dependsOn buildZip
48 changes: 23 additions & 25 deletions sample-apps/java-basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<name>java-basic-function</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
Expand All @@ -18,35 +18,22 @@
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.17.1,)</version>
<scope>test</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>[2.17.1,)</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>[2.17.1,)</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependency>
</dependencies>

<build>
Expand All @@ -61,6 +48,17 @@
<version>3.2.2</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*</exclude>
<exclude>META-INF/versions/**</exclude>
<exclude>META-INF/services/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
Expand All @@ -76,8 +74,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
Loading