Skip to content

Commit 8118eb8

Browse files
committed
Add changes back in
1 parent c5ced4f commit 8118eb8

File tree

11 files changed

+582
-96
lines changed

11 files changed

+582
-96
lines changed

examples/powertools-examples-core-utilities/cdk/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ For general information on the deployed example itself, you can refer to the par
66

77
## Configuration
88
CDK uses the following project structure:
9-
- [app](app) - stores the source code of your application, which is similar between all examples
10-
- [infra](infra) - stores the definition of your infrastructure
11-
- [cdk.json](infra/cdk.json) - tells the CDK Toolkit how to execute your app
12-
- [CdkApp](infra/src/main/java/cdk/CdkApp.java) - bootstraps your stack, taking AWS `account` and `region` as input
13-
- [CdkStack](infra/src/main/java/cdk/CdkStack.java) - defines the Lambda function to be deployed as well as API Gateway for it.
9+
- [app](./app) - stores the source code of your application, which is similar between all examples
10+
- [infra](./infra) - stores the definition of your infrastructure
11+
- [cdk.json](./infra/cdk.json) - tells the CDK Toolkit how to execute your app
12+
- [CdkApp](./infra/src/main/java/cdk/CdkApp.java) - bootstraps your stack, taking AWS `account` and `region` as input
13+
- [CdkStack](./infra/src/main/java/cdk/CdkStack.java) - defines the Lambda function to be deployed as well as API Gateway for it.
1414

1515
It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.
1616

examples/powertools-examples-core-utilities/cdk/app/pom.xml

+69-78
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>software.amazon.lambda.examples</groupId>
6-
<version>1.17.0</version>
6+
<version>1.20.0</version>
77
<artifactId>powertools-examples-core-utilities-cdk</artifactId>
88
<packaging>jar</packaging>
9-
10-
<name>Powertools for AWS Lambda (Java) library Examples - Core Utilities (logging, tracing, metrics) with CDK</name>
9+
<name>Powertools for AWS Lambda (Java) library Examples - Core</name>
1110

1211
<properties>
1312
<log4j.version>2.20.0</log4j.version>
@@ -40,7 +39,7 @@
4039
<dependency>
4140
<groupId>com.amazonaws</groupId>
4241
<artifactId>aws-lambda-java-events</artifactId>
43-
<version>3.11.2</version>
42+
<version>3.11.3</version>
4443
</dependency>
4544
<dependency>
4645
<groupId>org.apache.logging.log4j</groupId>
@@ -67,80 +66,72 @@
6766
</dependencies>
6867

6968
<build>
70-
<finalName>helloworld-lambda</finalName>
71-
<plugins>
72-
<plugin>
73-
<groupId>dev.aspectj</groupId>
74-
<artifactId>aspectj-maven-plugin</artifactId>
75-
<version>1.13.1</version>
76-
<configuration>
77-
<source>${maven.compiler.source}</source>
78-
<target>${maven.compiler.target}</target>
79-
<complianceLevel>${maven.compiler.target}</complianceLevel>
80-
<aspectLibraries>
81-
<aspectLibrary>
82-
<groupId>software.amazon.lambda</groupId>
83-
<artifactId>powertools-tracing</artifactId>
84-
</aspectLibrary>
85-
<aspectLibrary>
86-
<groupId>software.amazon.lambda</groupId>
87-
<artifactId>powertools-logging</artifactId>
88-
</aspectLibrary>
89-
<aspectLibrary>
90-
<groupId>software.amazon.lambda</groupId>
91-
<artifactId>powertools-metrics</artifactId>
92-
</aspectLibrary>
93-
</aspectLibraries>
94-
</configuration>
95-
<executions>
96-
<execution>
97-
<goals>
98-
<goal>compile</goal>
99-
</goals>
100-
</execution>
101-
</executions>
102-
<dependencies>
103-
<dependency>
104-
<groupId>org.aspectj</groupId>
105-
<artifactId>aspectjtools</artifactId>
106-
<version>${aspectj.version}</version>
107-
</dependency>
108-
</dependencies>
109-
</plugin>
110-
<plugin>
111-
<groupId>org.apache.maven.plugins</groupId>
112-
<artifactId>maven-shade-plugin</artifactId>
113-
<version>3.5.0</version>
114-
<executions>
115-
<execution>
116-
<phase>package</phase>
117-
<goals>
118-
<goal>shade</goal>
119-
</goals>
120-
<configuration>
121-
<transformers>
122-
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
123-
</transformers>
124-
</configuration>
125-
</execution>
126-
</executions>
127-
<dependencies>
128-
<dependency>
129-
<groupId>org.apache.logging.log4j</groupId>
130-
<artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
131-
<version>0.1.0</version>
132-
</dependency>
133-
</dependencies>
134-
</plugin>
135-
<!-- Don't deploy the example -->
136-
<plugin>
137-
<groupId>org.apache.maven.plugins</groupId>
138-
<artifactId>maven-deploy-plugin</artifactId>
139-
<configuration>
140-
<skip>true</skip>
141-
</configuration>
142-
</plugin>
143-
</plugins>
69+
<finalName>helloworld-lambda</finalName>
70+
<plugins>
71+
<plugin>
72+
<groupId>dev.aspectj</groupId>
73+
<artifactId>aspectj-maven-plugin</artifactId>
74+
<version>1.13.1</version>
75+
<configuration>
76+
<source>${maven.compiler.source}</source>
77+
<target>${maven.compiler.target}</target>
78+
<complianceLevel>${maven.compiler.target}</complianceLevel>
79+
<aspectLibraries>
80+
<aspectLibrary>
81+
<groupId>software.amazon.lambda</groupId>
82+
<artifactId>powertools-tracing</artifactId>
83+
</aspectLibrary>
84+
<aspectLibrary>
85+
<groupId>software.amazon.lambda</groupId>
86+
<artifactId>powertools-logging</artifactId>
87+
</aspectLibrary>
88+
<aspectLibrary>
89+
<groupId>software.amazon.lambda</groupId>
90+
<artifactId>powertools-metrics</artifactId>
91+
</aspectLibrary>
92+
</aspectLibraries>
93+
</configuration>
94+
<executions>
95+
<execution>
96+
<goals>
97+
<goal>compile</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
<dependencies>
102+
<dependency>
103+
<groupId>org.aspectj</groupId>
104+
<artifactId>aspectjtools</artifactId>
105+
<version>${aspectj.version}</version>
106+
</dependency>
107+
</dependencies>
108+
</plugin>
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-shade-plugin</artifactId>
112+
<version>3.5.0</version>
113+
<executions>
114+
<execution>
115+
<phase>package</phase>
116+
<goals>
117+
<goal>shade</goal>
118+
</goals>
119+
<configuration>
120+
<transformers>
121+
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
122+
</transformers>
123+
</configuration>
124+
</execution>
125+
</executions>
126+
<dependencies>
127+
<dependency>
128+
<groupId>org.apache.logging.log4j</groupId>
129+
<artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
130+
<version>0.1.0</version>
131+
</dependency>
132+
</dependencies>
133+
</plugin>
134+
</plugins>
144135
</build>
145136
<profiles>
146137
<!-- Use a profile to enforce AspectJ version 1.9.7 if we are Java 1.8 otherwise we'll get class

examples/powertools-examples-core-utilities/cdk/app/src/main/java/helloworld/App.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@
4646
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4747
private final static Logger log = LogManager.getLogger(App.class);
4848

49-
// This is controlled by POWERTOOLS_LOGGER_SAMPLE_RATE environment variable
50-
// @Logging(logEvent = true, samplingRate = 0.7)
51-
// This is controlled by POWERTOOLS_METRICS_NAMESPACE environment variable
52-
// @Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
53-
// This is controlled by POWERTOOLS_TRACER_CAPTURE_ERROR environment variable
49+
@Logging(logEvent = true, samplingRate = 0.7)
5450
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
51+
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
5552
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
5653
Map<String, String> headers = new HashMap<>();
5754

@@ -87,25 +84,18 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
8784
return response
8885
.withStatusCode(200)
8986
.withBody(output);
90-
<<<<<<<< HEAD:examples/powertools-examples-core-utilities/cdk/app/src/main/java/helloworld/App.java
9187
} catch (IOException e) {
92-
========
93-
} catch (RuntimeException | IOException e) {
94-
>>>>>>>> main:examples/powertools-examples-core/serverless/src/main/java/helloworld/App.java
9588
return response
9689
.withBody("{}")
9790
.withStatusCode(500);
9891
}
9992
}
10093

101-
<<<<<<<< HEAD:examples/powertools-examples-core-utilities/cdk/app/src/main/java/helloworld/App.java
10294
@Tracing
10395
private void log() {
10496
log.info("inside threaded logging for function");
10597
}
10698

107-
========
108-
>>>>>>>> main:examples/powertools-examples-core/serverless/src/main/java/helloworld/App.java
10999
@Tracing(namespace = "getPageContents", captureMode = CaptureMode.DISABLED)
110100
private String getPageContents(String address) throws IOException {
111101
URL url = new URL(address);

examples/powertools-examples-core-utilities/gradle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You can also use `sam init` to create a new Gradle-powered Powertools applicatio
88
and then **Hello World Example with Powertools for AWS Lambda**, **Java 17** runtime, and finally **gradle**.
99

1010

11-
For general information on the deployed example itself, you can refer to the parent [README](../../powertools-examples-core/README.md)
11+
For general information on the deployed example itself, you can refer to the parent [README](../README.md)
1212

1313
## Configuration
1414
SAM uses [template.yaml](template.yaml) to define the application's AWS resources.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Powertools for AWS Lambda (Java) - Core Utilities Example with Serverless Framework
2+
3+
This project demonstrates the Lambda for Powertools Java module deployed using [Serverless Framework](https://www.serverless.com/framework).
4+
For general information on the deployed example itself, you can refer to the parent [README](../README.md).
5+
To install Serverless Framework if you don't have it yet, you can follow the [Getting Started Guide](https://www.serverless.com/framework/docs/getting-started).
6+
7+
## Configuration
8+
Serverless Framework uses [serverless.yml](./serverless.yml) to define the application's AWS resources.
9+
This file defines the Lambda function to be deployed as well as API Gateway for it.
10+
11+
It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.
12+
13+
14+
## Deploy the sample application
15+
16+
To deploy the app, simply run the following commands:
17+
```bash
18+
mvn package && sls deploy
19+
```
20+
21+
## Useful commands
22+
23+
Deploy a single function
24+
```bash
25+
sls deploy function -f hello
26+
```

0 commit comments

Comments
 (0)