Skip to content

fix(example): Update the example to v1.2.0 #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2021
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
24 changes: 12 additions & 12 deletions example/HelloWorldFunction/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ repositories {
}

dependencies {
implementation 'software.amazon.lambda:powertools-tracing:1.0.0'
aspectpath 'software.amazon.lambda:powertools-tracing:1.0.0'
implementation 'software.amazon.lambda:powertools-tracing:1.2.0'
aspectpath 'software.amazon.lambda:powertools-tracing:1.2.0'

implementation 'software.amazon.lambda:powertools-logging:1.0.0'
aspectpath 'software.amazon.lambda:powertools-logging:1.0.0'
implementation 'software.amazon.lambda:powertools-logging:1.2.0'
aspectpath 'software.amazon.lambda:powertools-logging:1.2.0'

implementation 'software.amazon.lambda:powertools-metrics:1.0.0'
aspectpath 'software.amazon.lambda:powertools-metrics:1.0.0'
implementation 'software.amazon.lambda:powertools-metrics:1.2.0'
aspectpath 'software.amazon.lambda:powertools-metrics:1.2.0'

implementation 'software.amazon.lambda:powertools-sqs:1.0.0'
aspectpath 'software.amazon.lambda:powertools-sqs:1.0.0'
implementation 'software.amazon.lambda:powertools-sqs:1.2.0'
aspectpath 'software.amazon.lambda:powertools-sqs:1.2.0'

implementation 'software.amazon.lambda:powertools-parameters:1.0.0'
aspectpath 'software.amazon.lambda:powertools-parameters:1.0.0'
implementation 'software.amazon.lambda:powertools-parameters:1.2.0'
aspectpath 'software.amazon.lambda:powertools-parameters:1.2.0'

implementation 'software.amazon.lambda:powertools-validation:1.0.0'
aspectpath 'software.amazon.lambda:powertools-validation:1.0.0'
implementation 'software.amazon.lambda:powertools-validation:1.2.0'
aspectpath 'software.amazon.lambda:powertools-validation:1.2.0'

implementation 'com.amazonaws:aws-lambda-java-core:1.2.0'
implementation 'com.amazonaws:aws-lambda-java-events:3.1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified example/HelloWorldFunction/gradlew
100644 → 100755
Empty file.
130 changes: 65 additions & 65 deletions example/HelloWorldFunction/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>helloworld</groupId>
<artifactId>HelloWorld</artifactId>
Expand Down Expand Up @@ -49,9 +49,9 @@
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.1.0</version>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand All @@ -70,70 +70,70 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<!-- Refer https://github.com/awslabs/aws-lambda-powertools-java/issues/50 -->
<groupId>com.nickwongdev</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.12.6</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<aspectLibraries>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-tracing</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-logging</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-metrics</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-sqs</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-validation</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<plugins>
<plugin>
<!-- Refer https://github.com/awslabs/aws-lambda-powertools-java/issues/50 -->
<groupId>com.nickwongdev</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.12.6</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<aspectLibraries>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-tracing</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-logging</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-metrics</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-sqs</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-validation</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
19 changes: 7 additions & 12 deletions example/HelloWorldFunction/src/main/java/helloworld/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import software.amazon.lambda.powertools.logging.LoggingUtils;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.CaptureMode;
import software.amazon.lambda.powertools.tracing.TracingUtils;
import software.amazon.lambda.powertools.tracing.Tracing;

Expand All @@ -33,11 +34,10 @@
* Handler for requests to Lambda function.
*/
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

Logger log = LogManager.getLogger();
private final static Logger log = LogManager.getLogger();

@Logging(logEvent = true, samplingRate = 0.7)
@Tracing(captureError = false, captureResponse = false)
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
Map<String, String> headers = new HashMap<>();
Expand Down Expand Up @@ -84,13 +84,9 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
}

private void threadOption1() throws InterruptedException {
Entity traceEntity = AWSXRay.getTraceEntity();
Thread thread = new Thread(() -> {
AWSXRay.setTraceEntity(traceEntity);
log();
});
thread.start();
thread.join();
final Entity traceEntity = AWSXRay.getTraceEntity();
assert traceEntity != null;
traceEntity.run(new Thread(this::log));
}

private void threadOption2() throws InterruptedException {
Expand All @@ -108,8 +104,7 @@ private void log() {
log.info("inside threaded logging for function");
}


@Tracing(namespace = "getPageContents", captureResponse = false, captureError = false)
@Tracing(namespace = "getPageContents", captureMode = CaptureMode.DISABLED)
private String getPageContents(String address) throws IOException {
URL url = new URL(address);
putMetadata("getPageContents", address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import static software.amazon.lambda.powertools.parameters.transform.Transformer.json;

public class AppParams implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

Logger log = LogManager.getLogger();
private final static Logger log = LogManager.getLogger();

SSMProvider ssmProvider = ParamManager.getSsmProvider();
SecretsProvider secretsProvider = ParamManager.getSecretsProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;

public class AppSqsEvent implements RequestHandler<SQSEvent, String> {
private static final Logger LOG = LogManager.getLogger(AppSqsEvent.class);
private static final Logger log = LogManager.getLogger(AppSqsEvent.class);

@Override
@SqsBatch(SampleMessageHandler.class)
@Logging(logEvent = true)
@Override
public String handleRequest(SQSEvent input, Context context) {
return "{\"statusCode\": 200}";
}

public class SampleMessageHandler implements SqsMessageHandler<Object> {
public static class SampleMessageHandler implements SqsMessageHandler<Object> {

@Override
public String process(SQSMessage message) {
if("19dd0b57-b21e-4ac1-bd88-01bbb068cb99".equals(message.getMessageId())) {
throw new RuntimeException(message.getMessageId());
}
LOG.info("Processing message with details {}", message);
log.info("Processing message with details {}", message);
return message.getMessageId();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static java.util.Collections.emptyList;

public class AppSqsEventUtil implements RequestHandler<SQSEvent, List<String>> {
private static final Logger LOG = LogManager.getLogger(AppSqsEventUtil.class);
private static final Logger log = LogManager.getLogger(AppSqsEventUtil.class);

@Override
public List<String> handleRequest(SQSEvent input, Context context) {
Expand All @@ -24,15 +24,15 @@ public List<String> handleRequest(SQSEvent input, Context context) {
throw new RuntimeException(message.getMessageId());
}

LOG.info("Processing message with details {}", message);
log.info("Processing message with details {}", message);
return message.getMessageId();
});

} catch (SQSBatchProcessingException e) {
LOG.info("Exception details {}", e.getMessage(), e);
LOG.info("Success message Returns{}", e.successMessageReturnValues());
LOG.info("Failed messages {}", e.getFailures());
LOG.info("Failed messages Reasons {}", e.getExceptions());
log.info("Exception details {}", e.getMessage(), e);
log.info("Success message Returns{}", e.successMessageReturnValues());
log.info("Failed messages {}", e.getFailures());
log.info("Failed messages Reasons {}", e.getExceptions());
return emptyList();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static java.util.Optional.of;

public final class LambdaHandlerProcessor {
// SERVICE_NAME cannot be final for testing purposes
private static String SERVICE_NAME = null != System.getenv("POWERTOOLS_SERVICE_NAME")
? System.getenv("POWERTOOLS_SERVICE_NAME") : "service_undefined";
private static Boolean IS_COLD_START = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public BaseProvider(CacheManager cacheManager) {
* Retrieve multiple parameter values from the underlying parameter store.<br />
* Abstract: Implement this method in a child class of {@link BaseProvider}
*
* @param path
* @return
* @param path Parameter store path
* @return Return map of parameter name value pairs
*/
protected abstract Map<String, String> getMultipleValues(String path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class ParamManager {
private static final CacheManager cacheManager = new CacheManager();
private static final TransformationManager transformationManager = new TransformationManager();

// NOTE: For testing purposes `providers` cannot be final
private static ConcurrentHashMap<Class<? extends BaseProvider>, BaseProvider> providers = new ConcurrentHashMap<>();

/**
Expand All @@ -43,7 +44,7 @@ public static <T extends BaseProvider> T getProvider(Class<T> providerClass) {
if (providerClass == null) {
throw new IllegalStateException("providerClass cannot be null.");
}
return (T) providers.computeIfAbsent(providerClass, (k) -> createProvider(k));
return (T) providers.computeIfAbsent(providerClass, ParamManager::createProvider);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
String outboundSchema() default "";

/**
* path to the subelement
* path to the sub element
*/
String envelope() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
*/
package software.amazon.lambda.powertools.validation;

import com.fasterxml.jackson.core.JsonProcessingException;

import java.io.IOException;

public class ValidationException extends RuntimeException {

private static final long serialVersionUID = 1133341411263381508L;
Expand Down