Skip to content

Commit cd5e78e

Browse files
committed
updated documentation
Updated documentation to reflect aws-lambda-java-events and aws-lambda-java-log4j2 updates.
1 parent e81c824 commit cd5e78e

File tree

3 files changed

+284
-5
lines changed

3 files changed

+284
-5
lines changed

README.md

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
# AWS Lambda Java Support Libraries
1+
# AWS Lambda Java Support Libraries
22
Interface definitions for Java code running on the AWS Lambda platform.
33

44
For issues and questions, you can start with our [FAQ](https://aws.amazon.com/lambda/faqs/) and the [AWS forums](https://forums.aws.amazon.com/forum.jspa?forumID=186)
55

66
To get started writing AWS Lambda functions in Java, check out the [official documentation] (http://docs.aws.amazon.com/lambda/latest/dg/java-gs.html).
77

8+
# Disclaimer of use
9+
10+
Each of the supplied packages should be used without modification. Removing
11+
dependencies, adding conflicting dependencies, or selectively including classes
12+
from the packages can result in unexpected behavior, which the AWS Lambda team
13+
is not responsible for.
14+
15+
# Recent Updates!
16+
17+
* ### [2017 Java Events Update](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events)
18+
* ### [Log4j2 Support](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2)
19+
20+
# Where to get packages
821
___
922

1023
[Maven](https://maven.apache.org)
@@ -18,7 +31,7 @@ ___
1831
<dependency>
1932
<groupId>com.amazonaws</groupId>
2033
<artifactId>aws-lambda-java-events</artifactId>
21-
<version>1.3.0</version>
34+
<version>2.0</version>
2235
</dependency>
2336
<dependency>
2437
<groupId>com.amazonaws</groupId>
@@ -36,7 +49,7 @@ ___
3649

3750
```groovy
3851
'com.amazonaws:aws-lambda-java-core:1.1.0'
39-
'com.amazonaws:aws-lambda-java-events:1.3.0'
52+
'com.amazonaws:aws-lambda-java-events:2.0'
4053
'com.amazonaws:aws-lambda-java-log4j:1.0.0'
4154
'com.amazonaws:aws-lambda-java-log4j2:1.0.0'
4255
```
@@ -45,7 +58,7 @@ ___
4558

4659
```clojure
4760
[com.amazonaws/aws-lambda-java-core "1.1.0"]
48-
[com.amazonaws/aws-lambda-java-events "1.3.0"]
61+
[com.amazonaws/aws-lambda-java-events "2.0"]
4962
[com.amazonaws/aws-lambda-java-log4j "1.0.0"]
5063
[com.amazonaws/aws-lambda-java-log4j2 "1.0.0"]
5164
```
@@ -54,7 +67,26 @@ ___
5467

5568
```scala
5669
"com.amazonaws" % "aws-lambda-java-core" % "1.1.0"
57-
"com.amazonaws" % "aws-lambda-java-events" % "1.3.0"
70+
"com.amazonaws" % "aws-lambda-java-events" % "2.0"
5871
"com.amazonaws" % "aws-lambda-java-log4j" % "1.0.0"
5972
"com.amazonaws" % "aws-lambda-java-log4j2" % "1.0.0"
6073
```
74+
75+
# Using aws-lambda-java-core
76+
77+
This package defines the Lambda [Context](http://docs.aws.amazon.com/lambda/latest/dg/java-context-object.html)
78+
object as well as [interfaces](http://docs.aws.amazon.com/lambda/latest/dg/java-handler-using-predefined-interfaces.html) that Lambda accepts.
79+
80+
# Using aws-lambda-java-events
81+
82+
This package defines [event sources](http://docs.aws.amazon.com/lambda/latest/dg/intro-invocation-modes.html) that AWS Lambda natively accepts. See the [documentation](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events) for more information.
83+
84+
# Using aws-lambda-java-log4j2
85+
86+
This package defines the Lambda adapter to use with log4j version 2. See
87+
[documentation](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2) for how to use the adapter.
88+
89+
# Using aws-lambda-java-log4j (Not recommended)
90+
91+
This package defines the Lambda adapter to use with log4j version 1. See
92+
the [official documentation](http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-wt-logging-using-log4j) for how to use this adapter.

aws-lambda-java-events/README.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# AWS Lambda Java Events v2.0
2+
3+
### New Event Models Supported
4+
* APIGatewayProxyRequestEvent
5+
* APIGatewayProxyResponseEvent
6+
* CloudFrontEvent
7+
* CloudWatchLogsEvent
8+
* CodeCommitEvent
9+
* IoTButtonEvent
10+
* KinesisFirehoseEvent
11+
* LexEvent
12+
* ScheduledEvent
13+
14+
### New package inclusion model
15+
The old package inclusion model required users to pull unused dependencies into
16+
their package. We have removed this inclusion so that users' jars will be
17+
smaller, which will results in reduced latency times. Customers using older
18+
versions do not need to make any changes to their existing code.
19+
20+
The following event models do not require any SDK dependencies
21+
* APIGatewayProxyRequestEvent
22+
* APIGatewayProxyResponseEvent
23+
* CloudFrontEvent
24+
* CloudWatchLogsEvent
25+
* CodeCommitEvent
26+
* CognitoEvent
27+
* ConfigEvent
28+
* IoTButtonEvent
29+
* KinesisFirehoseEvent
30+
* LexEvent
31+
* ScheduledEvent
32+
* SNSEvent
33+
34+
so the dependencies section in the pom.xml file would like this
35+
36+
```xml
37+
<dependencies>
38+
...
39+
<dependency>
40+
<groupId>com.amazonaws</groupId>
41+
<artifactId>aws-lambda-java-core</artifactId>
42+
<version>1.1.0</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.amazonaws</groupId>
46+
<artifactId>aws-lambda-java-events</artifactId>
47+
<version>2.0</version>
48+
</dependency>
49+
...
50+
</dependencies>
51+
```
52+
53+
#### S3 Event
54+
55+
For the S3 event the pom would look like this:
56+
57+
```xml
58+
<dependencies>
59+
...
60+
<dependency>
61+
<groupId>com.amazonaws</groupId>
62+
<artifactId>aws-lambda-java-core</artifactId>
63+
<version>1.1.0</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.amazonaws</groupId>
67+
<artifactId>aws-lambda-java-events</artifactId>
68+
<version>2.0</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.amazonaws</groupId>
72+
<artifactId>aws-java-sdk-s3</artifactId>
73+
<version>1.11.163</version>
74+
</dependency>
75+
...
76+
</dependencies>
77+
```
78+
79+
#### Kinesis Event
80+
81+
For the Kinesis event
82+
83+
```xml
84+
<dependencies>
85+
....
86+
<dependency>
87+
<groupId>com.amazonaws</groupId>
88+
<artifactId>aws-lambda-java-core</artifactId>
89+
<version>1.1.0</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>com.amazonaws</groupId>
93+
<artifactId>aws-lambda-java-events</artifactId>
94+
<version>2.0</version>
95+
</dependency>
96+
<dependency>
97+
<groupId>com.amazonaws</groupId>
98+
<artifactId>aws-java-sdk-kinesis</artifactId>
99+
<version>1.11.163</version>
100+
</dependency>
101+
...
102+
</dependencies>
103+
```
104+
105+
#### Dynamodb Event
106+
107+
For the Dynamodb event
108+
109+
```xml
110+
<dependencies>
111+
...
112+
<dependency>
113+
<groupId>com.amazonaws</groupId>
114+
<artifactId>aws-lambda-java-core</artifactId>
115+
<version>1.1.0</version>
116+
</dependency>
117+
<dependency>
118+
<groupId>com.amazonaws</groupId>
119+
<artifactId>aws-lambda-java-events</artifactId>
120+
<version>2.0</version>
121+
</dependency>
122+
<dependency>
123+
<groupId>com.amazonaws</groupId>
124+
<artifactId>aws-java-sdk-dynamodb</artifactId>
125+
<version>1.11.163</version>
126+
</dependency>
127+
...
128+
</dependencies>
129+
```

aws-lambda-java-log4j2/README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Using log4j2 with AWS Lambda
2+
3+
### 1. Pull in log4j2 dependencies
4+
5+
Example for Maven pom.xml
6+
7+
```xml
8+
<dependencies>
9+
...
10+
<dependency>
11+
<groupId>com.amazonaws</groupId>
12+
<artifactId>aws-lambda-java-log4j2</artifactId>
13+
<version>1.0.0</version>
14+
</dependency>
15+
<dependency>
16+
<groupId>org.apache.logging.log4j</groupId>
17+
<artifactId>log4j-core</artifactId>
18+
<version>2.8.2</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.apache.logging.log4j</groupId>
22+
<artifactId>log4j-api</artifactId>
23+
<version>2.8.2</version>
24+
</dependency>
25+
....
26+
</dependencies>
27+
```
28+
29+
If using maven shade plugin, set the plugin configuration as follows
30+
31+
```xml
32+
<plugins>
33+
...
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-shade-plugin</artifactId>
37+
<version>2.4.3</version>
38+
<executions>
39+
<execution>
40+
<phase>package</phase>
41+
<goals>
42+
<goal>shade</goal>
43+
</goals>
44+
<configuration>
45+
<transformers>
46+
<transformer
47+
implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
48+
</transformer>
49+
</transformers>
50+
</configuration>
51+
</execution>
52+
</executions>
53+
<dependencies>
54+
<dependency>
55+
<groupId>com.github.edwgiz</groupId>
56+
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
57+
<version>2.8.1</version>
58+
</dependency>
59+
</dependencies>
60+
</plugin>
61+
...
62+
</plugins>
63+
```
64+
65+
### 2. Configure log4j2 using log4j2.xml file
66+
67+
Add the following file `<project-dir>/src/main/resources/log4j2.xml`
68+
69+
```xml
70+
<?xml version="1.0" encoding="UTF-8"?>
71+
<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2.LambdaAppender">
72+
<Appenders>
73+
<Lambda name="Lambda">
74+
<PatternLayout>
75+
<pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n</pattern>
76+
</PatternLayout>
77+
</Lambda>
78+
</Appenders>
79+
<Loggers>
80+
<Root level="debug">
81+
<AppenderRef ref="Lambda" />
82+
</Root>
83+
</Loggers>
84+
</Configuration>
85+
```
86+
87+
### 3. Example code
88+
89+
```java
90+
package example;
91+
92+
import com.amazonaws.services.lambda.runtime.Context;
93+
94+
import org.apache.logging.log4j.LogManager;
95+
import org.apache.logging.log4j.Logger;
96+
97+
public class Hello {
98+
// Initialize the Log4j logger.
99+
static final Logger logger = LogManager.getLogger(Hello.class);
100+
101+
public String myHandler(String name, Context context) {
102+
// System.out: One log statement but with a line break (AWS Lambda writes two events to CloudWatch).
103+
System.out.println("log data from stdout \n this is continuation of system.out");
104+
105+
// System.err: One log statement but with a line break (AWS Lambda writes two events to CloudWatch).
106+
System.err.println("log data from stderr. \n this is a continuation of system.err");
107+
108+
// Use log4j to log the same thing as above and AWS Lambda will log only one event in CloudWatch.
109+
logger.debug("log data from log4j debug \n this is continuation of log4j debug");
110+
111+
logger.error("log data from log4j err. \n this is a continuation of log4j.err");
112+
113+
// Return will include the log stream name so you can look
114+
// up the log later.
115+
return String.format("Hello %s. log stream = %s", name, context.getLogStreamName());
116+
}
117+
}
118+
```

0 commit comments

Comments
 (0)