From 53aeaa93b13ec289d666bbe387d58e545e89440f Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 17:54:30 +0200 Subject: [PATCH 01/22] fix java:S2177 --- .../lambda/powertools/logging/internal/LambdaJsonLayout.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java index 578937231..676e6ed82 100644 --- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java +++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java @@ -187,7 +187,7 @@ public static LambdaJsonLayout createDefaultLayout() { @Override public Object wrapLogEvent(final LogEvent event) { - Map additionalFieldsMap = resolveAdditionalFields(event); + Map additionalFieldsMap = getAdditionalFields(event); // This class combines LogEvent with AdditionalFields during serialization return new LogEventWithAdditionalFields(event, additionalFieldsMap); } @@ -200,7 +200,7 @@ public void toSerializable(final LogEvent event, final Writer writer) throws IOE super.toSerializable(event, writer); } - private Map resolveAdditionalFields(LogEvent logEvent) { + private Map getAdditionalFields(LogEvent logEvent) { // Note: LinkedHashMap retains order final Map additionalFieldsMap = new LinkedHashMap<>(additionalFields.length); From 81f735c1f9746cb28d468f2cc18549f4b68efde0 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 17:55:48 +0200 Subject: [PATCH 02/22] fix java:S5833 --- .../lambda/powertools/utilities/EventDeserializerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java index 5055d7086..e7b9eb87d 100644 --- a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java +++ b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java @@ -203,8 +203,8 @@ public void testDeserializeProductAsProduct_shouldReturnProduct() { private void assertProduct(Product product) { assertThat(product) - .isEqualTo(new Product(1234, "product", 42)) - .usingRecursiveComparison(); + .usingRecursiveComparison() + .isEqualTo(new Product(1234, "product", 42)); } @ParameterizedTest From 3c7f10e00bc0df6f463eaf8d67dacf90298b0c58 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:00:25 +0200 Subject: [PATCH 03/22] fix java:S1192 --- .../src/main/java/helloworld/App.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java b/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java index c7744cd5a..a5763a522 100644 --- a/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java +++ b/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java @@ -9,7 +9,11 @@ import software.amazon.awssdk.core.waiters.WaiterResponse; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.s3.S3Client; -import software.amazon.awssdk.services.s3.model.*; +import software.amazon.awssdk.services.s3.model.CreateBucketRequest; +import software.amazon.awssdk.services.s3.model.DeleteBucketRequest; +import software.amazon.awssdk.services.s3.model.HeadBucketRequest; +import software.amazon.awssdk.services.s3.model.HeadBucketResponse; +import software.amazon.awssdk.services.s3.model.NoSuchBucketException; import software.amazon.awssdk.services.s3.waiters.S3Waiter; import software.amazon.lambda.powertools.cloudformation.AbstractCustomResourceHandler; import software.amazon.lambda.powertools.cloudformation.Response; @@ -22,6 +26,8 @@ public class App extends AbstractCustomResourceHandler { private final static Logger log = LogManager.getLogger(App.class); + public static final String CFN_CUSTOM_RESOURCE_EVENT_CANNOT_BE_NULL = "cloudFormationCustomResourceEvent cannot be null."; + public static final String BUCKET_NAME = "BucketName"; private final S3Client s3Client; public App() { @@ -40,11 +46,11 @@ public App() { @Override protected Response create(CloudFormationCustomResourceEvent cloudFormationCustomResourceEvent, Context context) { // Validate the CloudFormation Custom Resource event - Objects.requireNonNull(cloudFormationCustomResourceEvent, "cloudFormationCustomResourceEvent cannot be null."); - Objects.requireNonNull(cloudFormationCustomResourceEvent.getResourceProperties().get("BucketName"), "BucketName cannot be null."); + Objects.requireNonNull(cloudFormationCustomResourceEvent, CFN_CUSTOM_RESOURCE_EVENT_CANNOT_BE_NULL); + Objects.requireNonNull(cloudFormationCustomResourceEvent.getResourceProperties().get(BUCKET_NAME), "BucketName cannot be null."); log.info(cloudFormationCustomResourceEvent); - String bucketName = (String) cloudFormationCustomResourceEvent.getResourceProperties().get("BucketName"); + String bucketName = (String) cloudFormationCustomResourceEvent.getResourceProperties().get(BUCKET_NAME); log.info("Bucket Name {}", bucketName); try { // Create the S3 bucket with the given bucketName @@ -69,8 +75,8 @@ protected Response create(CloudFormationCustomResourceEvent cloudFormationCustom @Override protected Response update(CloudFormationCustomResourceEvent cloudFormationCustomResourceEvent, Context context) { // Validate the CloudFormation Custom Resource event - Objects.requireNonNull(cloudFormationCustomResourceEvent, "cloudFormationCustomResourceEvent cannot be null."); - Objects.requireNonNull(cloudFormationCustomResourceEvent.getResourceProperties().get("BucketName"), "BucketName cannot be null."); + Objects.requireNonNull(cloudFormationCustomResourceEvent, CFN_CUSTOM_RESOURCE_EVENT_CANNOT_BE_NULL); + Objects.requireNonNull(cloudFormationCustomResourceEvent.getResourceProperties().get(BUCKET_NAME), "BucketName cannot be null."); log.info(cloudFormationCustomResourceEvent); // Get the physicalResourceId. physicalResourceId is the value returned to CloudFormation in the Create request, and passed in on subsequent requests (e.g. UPDATE or DELETE) @@ -78,7 +84,7 @@ protected Response update(CloudFormationCustomResourceEvent cloudFormationCustom log.info("Physical Resource ID {}", physicalResourceId); // Get the BucketName from the CloudFormation Event - String newBucketName = (String) cloudFormationCustomResourceEvent.getResourceProperties().get("BucketName"); + String newBucketName = (String) cloudFormationCustomResourceEvent.getResourceProperties().get(BUCKET_NAME); // Check if the physicalResourceId equals the new BucketName if (!physicalResourceId.equals(newBucketName)) { @@ -111,7 +117,7 @@ protected Response update(CloudFormationCustomResourceEvent cloudFormationCustom @Override protected Response delete(CloudFormationCustomResourceEvent cloudFormationCustomResourceEvent, Context context) { // Validate the CloudFormation Custom Resource event - Objects.requireNonNull(cloudFormationCustomResourceEvent, "cloudFormationCustomResourceEvent cannot be null."); + Objects.requireNonNull(cloudFormationCustomResourceEvent, CFN_CUSTOM_RESOURCE_EVENT_CANNOT_BE_NULL); Objects.requireNonNull(cloudFormationCustomResourceEvent.getPhysicalResourceId(), "PhysicalResourceId cannot be null."); log.info(cloudFormationCustomResourceEvent); From bb60312574310dee108be9b63e3cecda023fa99f Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:02:14 +0200 Subject: [PATCH 04/22] fix java:S115 --- .../persistence/DynamoDBPersistenceStore.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/DynamoDBPersistenceStore.java b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/DynamoDBPersistenceStore.java index 783b029bb..396a191bc 100644 --- a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/DynamoDBPersistenceStore.java +++ b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/DynamoDBPersistenceStore.java @@ -18,8 +18,15 @@ import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; -import software.amazon.awssdk.services.dynamodb.model.*; +import software.amazon.awssdk.services.dynamodb.model.AttributeValue; +import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException; +import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest; +import software.amazon.awssdk.services.dynamodb.model.GetItemRequest; +import software.amazon.awssdk.services.dynamodb.model.GetItemResponse; +import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; +import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest; import software.amazon.awssdk.utils.StringUtils; +import software.amazon.lambda.powertools.core.internal.LambdaConstants; import software.amazon.lambda.powertools.idempotency.Constants; import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyItemAlreadyExistsException; import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyItemNotFoundException; @@ -33,7 +40,6 @@ import java.util.stream.Stream; import static software.amazon.lambda.powertools.core.internal.LambdaConstants.AWS_REGION_ENV; -import static software.amazon.lambda.powertools.core.internal.LambdaConstants.LAMBDA_FUNCTION_NAME_ENV; import static software.amazon.lambda.powertools.idempotency.persistence.DataRecord.Status.INPROGRESS; /** @@ -261,11 +267,11 @@ public static Builder builder() { * You can also set a custom {@link DynamoDbClient} for further tuning. */ public static class Builder { - private static final String funcEnv = System.getenv(LAMBDA_FUNCTION_NAME_ENV); + private static final String LAMBDA_FUNCTION_NAME_ENV = System.getenv(LambdaConstants.LAMBDA_FUNCTION_NAME_ENV); private String tableName; private String keyAttr = "id"; - private String staticPkValue = String.format("idempotency#%s", funcEnv != null ? funcEnv : ""); + private String staticPkValue = String.format("idempotency#%s", LAMBDA_FUNCTION_NAME_ENV != null ? LAMBDA_FUNCTION_NAME_ENV : ""); private String sortKeyAttr; private String expiryAttr = "expiration"; From 1a2d2fdd23989eb25ca000380ab2c79e837eede3 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:05:47 +0200 Subject: [PATCH 05/22] fix java:S1186 --- .../logging/internal/AbstractJacksonLayoutCopy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java index c96d1383e..25c1b083c 100644 --- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java +++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java @@ -477,12 +477,12 @@ public boolean isIncludeLocation() { @Override public void setEndOfBatch(boolean endOfBatch) { - + // do nothing } @Override public void setIncludeLocation(boolean locationRequired) { - + // do nothing } @Override From 6d7c45898da15f37194f40d1db7e3ae211007432 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:06:32 +0200 Subject: [PATCH 06/22] fix java:S1192 --- .../powertools/parameters/DynamoDbProvider.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/DynamoDbProvider.java b/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/DynamoDbProvider.java index e09f23348..7ce9a37de 100644 --- a/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/DynamoDbProvider.java +++ b/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/DynamoDbProvider.java @@ -26,6 +26,7 @@ */ public class DynamoDbProvider extends BaseProvider { + private static final String VALUE = "value"; private final DynamoDbClient client; private final String tableName; @@ -50,17 +51,17 @@ protected String getValue(String key) { GetItemResponse resp = client.getItem(GetItemRequest.builder() .tableName(tableName) .key(Collections.singletonMap("id", AttributeValue.fromS(key))) - .attributesToGet("value") + .attributesToGet(VALUE) .build()); // If we have an item at the key, we should be able to get a 'val' out of it. If not it's // exceptional. // If we don't have an item at the key, we should return null. if (resp.hasItem() && !resp.item().values().isEmpty()) { - if (!resp.item().containsKey("value")) { + if (!resp.item().containsKey(VALUE)) { throw new DynamoDbProviderSchemaException("Missing 'value': " + resp.item().toString()); } - return resp.item().get("value").s(); + return resp.item().get(VALUE).s(); } return null; @@ -88,14 +89,14 @@ protected Map getMultipleValues(String path) { if (!i.containsKey("sk")) { throw new DynamoDbProviderSchemaException("Missing 'sk': " + i.toString()); } - if (!i.containsKey("value")) { + if (!i.containsKey(VALUE)) { throw new DynamoDbProviderSchemaException("Missing 'value': " + i.toString()); } }) .collect( Collectors.toMap( (i) -> i.get("sk").s(), - (i) -> i.get("value").s())); + (i) -> i.get(VALUE).s())); } From 4cc700b3b0d212e88afa7a24bb893001e8e879b8 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:11:36 +0200 Subject: [PATCH 07/22] fix java:S1186 --- .../amazon/lambda/powertools/core/internal/SystemWrapper.java | 1 + .../lambda/powertools/tracing/internal/SystemWrapper.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/SystemWrapper.java b/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/SystemWrapper.java index aef64378f..2211c3ad5 100644 --- a/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/SystemWrapper.java +++ b/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/SystemWrapper.java @@ -2,6 +2,7 @@ public class SystemWrapper { private SystemWrapper() { + // avoid instantiation, static methods } public static String getenv(String name) { diff --git a/powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/internal/SystemWrapper.java b/powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/internal/SystemWrapper.java index da1a92ced..2f56b792e 100644 --- a/powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/internal/SystemWrapper.java +++ b/powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/internal/SystemWrapper.java @@ -1,7 +1,8 @@ package software.amazon.lambda.powertools.tracing.internal; public class SystemWrapper { - public SystemWrapper() { + private SystemWrapper() { + // avoid instantiation, static methods } public static String getenv(String name) { From e153c16c85e5c70666639392e98a96427b37657f Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:13:20 +0200 Subject: [PATCH 08/22] fix java:S1186 --- .../src/main/java/org/demo/parameters/MyObject.java | 1 + .../java/software/amazon/lambda/powertools/e2e/Input.java | 1 + .../java/software/amazon/lambda/powertools/e2e/Input.java | 1 + .../java/software/amazon/lambda/powertools/e2e/Input.java | 1 + .../java/software/amazon/lambda/powertools/e2e/Input.java | 7 +++++-- .../java/software/amazon/lambda/powertools/e2e/Input.java | 1 + 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/powertools-examples-parameters/src/main/java/org/demo/parameters/MyObject.java b/examples/powertools-examples-parameters/src/main/java/org/demo/parameters/MyObject.java index 2cf145284..0e7df52ae 100644 --- a/examples/powertools-examples-parameters/src/main/java/org/demo/parameters/MyObject.java +++ b/examples/powertools-examples-parameters/src/main/java/org/demo/parameters/MyObject.java @@ -6,6 +6,7 @@ public class MyObject { private String code; public MyObject() { + // for deserialization } public long getId() { diff --git a/powertools-e2e-tests/handlers/idempotency/src/main/java/software/amazon/lambda/powertools/e2e/Input.java b/powertools-e2e-tests/handlers/idempotency/src/main/java/software/amazon/lambda/powertools/e2e/Input.java index c5c2a121e..f7d9c9a1a 100644 --- a/powertools-e2e-tests/handlers/idempotency/src/main/java/software/amazon/lambda/powertools/e2e/Input.java +++ b/powertools-e2e-tests/handlers/idempotency/src/main/java/software/amazon/lambda/powertools/e2e/Input.java @@ -8,6 +8,7 @@ public Input(String message) { } public Input() { + // for deserialization } public String getMessage() { diff --git a/powertools-e2e-tests/handlers/logging/src/main/java/software/amazon/lambda/powertools/e2e/Input.java b/powertools-e2e-tests/handlers/logging/src/main/java/software/amazon/lambda/powertools/e2e/Input.java index 83afbbd5a..2f3f6499e 100644 --- a/powertools-e2e-tests/handlers/logging/src/main/java/software/amazon/lambda/powertools/e2e/Input.java +++ b/powertools-e2e-tests/handlers/logging/src/main/java/software/amazon/lambda/powertools/e2e/Input.java @@ -7,6 +7,7 @@ public class Input { private Map keys; public Input() { + // for deserialization } public String getMessage() { diff --git a/powertools-e2e-tests/handlers/metrics/src/main/java/software/amazon/lambda/powertools/e2e/Input.java b/powertools-e2e-tests/handlers/metrics/src/main/java/software/amazon/lambda/powertools/e2e/Input.java index 5ff8a7125..1c3db289b 100644 --- a/powertools-e2e-tests/handlers/metrics/src/main/java/software/amazon/lambda/powertools/e2e/Input.java +++ b/powertools-e2e-tests/handlers/metrics/src/main/java/software/amazon/lambda/powertools/e2e/Input.java @@ -16,6 +16,7 @@ public void setMetrics(Map metrics) { } public Input() { + // for deserialization } diff --git a/powertools-e2e-tests/handlers/parameters/src/main/java/software/amazon/lambda/powertools/e2e/Input.java b/powertools-e2e-tests/handlers/parameters/src/main/java/software/amazon/lambda/powertools/e2e/Input.java index 7ea22143f..7e8041530 100644 --- a/powertools-e2e-tests/handlers/parameters/src/main/java/software/amazon/lambda/powertools/e2e/Input.java +++ b/powertools-e2e-tests/handlers/parameters/src/main/java/software/amazon/lambda/powertools/e2e/Input.java @@ -1,12 +1,15 @@ package software.amazon.lambda.powertools.e2e; -import java.util.Map; - public class Input { private String app; private String environment; private String key; + + public Input() { + // for deserialization + } + public void setApp(String app) { this.app = app; } diff --git a/powertools-e2e-tests/handlers/tracing/src/main/java/software/amazon/lambda/powertools/e2e/Input.java b/powertools-e2e-tests/handlers/tracing/src/main/java/software/amazon/lambda/powertools/e2e/Input.java index 29cf618ba..aabbab5e5 100644 --- a/powertools-e2e-tests/handlers/tracing/src/main/java/software/amazon/lambda/powertools/e2e/Input.java +++ b/powertools-e2e-tests/handlers/tracing/src/main/java/software/amazon/lambda/powertools/e2e/Input.java @@ -4,6 +4,7 @@ public class Input { private String message; public Input() { + // for deserialization } public String getMessage() { From 563011f09588794ba868b2486931a398d0ecbd35 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:18:46 +0200 Subject: [PATCH 09/22] fix AbstractCustomResourceHandler --- .../cloudformation/AbstractCustomResourceHandler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/AbstractCustomResourceHandler.java b/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/AbstractCustomResourceHandler.java index 7d3a43069..53a50bfa0 100644 --- a/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/AbstractCustomResourceHandler.java +++ b/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/AbstractCustomResourceHandler.java @@ -52,13 +52,13 @@ public final Response handleRequest(CloudFormationCustomResourceEvent event, Con String responseUrl = Objects.requireNonNull(event.getResponseUrl(), "Event must have a non-null responseUrl to be able to send the response."); - CloudFormationResponse client = buildResponseClient(); + CloudFormationResponse cloudFormationResponse = buildResponseClient(); Response response = null; try { response = getResponse(event, context); LOG.debug("Preparing to send response {} to {}.", response, responseUrl); - client.send(event, context, response); + cloudFormationResponse.send(event, context, response); } catch (IOException ioe) { LOG.error("Unable to send response {} to {}.", response, responseUrl, ioe); onSendFailure(event, context, response, ioe); @@ -70,7 +70,7 @@ public final Response handleRequest(CloudFormationCustomResourceEvent event, Con // In the case of a Update or Delete, a failure is sent with the existing PhysicalResourceId // indicating no change. // In the case of a Create, null will be set and changed to the Lambda LogStreamName before sending. - client.send(event, context, Response.failed(event.getPhysicalResourceId())); + cloudFormationResponse.send(event, context, Response.failed(event.getPhysicalResourceId())); } catch (Exception e) { // unable to generate response AND send the failure LOG.error("Unable to send failure response to {}.", responseUrl, e); @@ -91,7 +91,7 @@ private Response getResponse(CloudFormationCustomResourceEvent event, Context co case "Delete": return delete(event, context); default: - LOG.warn("Unexpected request type \"" + event.getRequestType() + "\" for event " + event); + LOG.warn("Unexpected request type \"{}\" for event {}", event.getRequestType(), event); return null; } } catch (RuntimeException e) { From e0b14f4f5053b37981f5ce7bf72ae9a3da87c62f Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:22:32 +0200 Subject: [PATCH 10/22] fix CloudFormationResponse --- .../CloudFormationResponse.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/CloudFormationResponse.java b/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/CloudFormationResponse.java index 39a86293b..18ec6bf90 100644 --- a/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/CloudFormationResponse.java +++ b/powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/CloudFormationResponse.java @@ -118,16 +118,14 @@ ObjectNode toObjectNode(JsonNode dataNode) { @Override public String toString() { - final StringBuffer sb = new StringBuffer("ResponseBody{"); - sb.append("status='").append(status).append('\''); - sb.append(", reason='").append(reason).append('\''); - sb.append(", physicalResourceId='").append(physicalResourceId).append('\''); - sb.append(", stackId='").append(stackId).append('\''); - sb.append(", requestId='").append(requestId).append('\''); - sb.append(", logicalResourceId='").append(logicalResourceId).append('\''); - sb.append(", noEcho=").append(noEcho); - sb.append('}'); - return sb.toString(); + return "ResponseBody{" + "status='" + status + '\'' + + ", reason='" + reason + '\'' + + ", physicalResourceId='" + physicalResourceId + '\'' + + ", stackId='" + stackId + '\'' + + ", requestId='" + requestId + '\'' + + ", logicalResourceId='" + logicalResourceId + '\'' + + ", noEcho=" + noEcho + + '}'; } } @@ -232,7 +230,7 @@ StringInputStream responseBodyStream(CloudFormationCustomResourceEvent event, } else { String physicalResourceId = resp.getPhysicalResourceId() != null ? resp.getPhysicalResourceId() : - event.getPhysicalResourceId() != null? event.getPhysicalResourceId() : context.getLogStreamName(); + (event.getPhysicalResourceId() != null ? event.getPhysicalResourceId() : context.getLogStreamName()); ResponseBody body = new ResponseBody(event, resp.getStatus(), physicalResourceId, resp.isNoEcho(), reason); LOG.debug("ResponseBody: {}", body); @@ -240,7 +238,6 @@ StringInputStream responseBodyStream(CloudFormationCustomResourceEvent event, return new StringInputStream(node.toString()); } } catch (RuntimeException e) { - LOG.error(e.getMessage()); throw new CustomResourceResponseException("Unable to generate response body.", e); } } From 0c79fcb86c7eff6432cfc6e5312a0763c8d459d1 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:23:30 +0200 Subject: [PATCH 11/22] fix LambdaConstants --- .../powertools/core/internal/LambdaConstants.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/LambdaConstants.java b/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/LambdaConstants.java index ea6a6ff44..9f03e20c6 100644 --- a/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/LambdaConstants.java +++ b/powertools-core/src/main/java/software/amazon/lambda/powertools/core/internal/LambdaConstants.java @@ -14,12 +14,23 @@ package software.amazon.lambda.powertools.core.internal; public class LambdaConstants { + + private LambdaConstants() { + // avoid instantiation, static fields + } + public static final String LAMBDA_FUNCTION_NAME_ENV = "AWS_LAMBDA_FUNCTION_NAME"; public static final String AWS_REGION_ENV = "AWS_REGION"; - // Also you can use AWS_LAMBDA_INITIALIZATION_TYPE to distinguish between on-demand and SnapStart initialization - // it's not recommended to use this env variable to initialize SDK clients or other resources. + /** + * @deprecated + * Also you can use AWS_LAMBDA_INITIALIZATION_TYPE to distinguish between on-demand and SnapStart initialization + * it's not recommended to use this env variable to initialize SDK clients or other resources. + */ @Deprecated public static final String AWS_LAMBDA_INITIALIZATION_TYPE = "AWS_LAMBDA_INITIALIZATION_TYPE"; + /** + * @deprecated see AWS_LAMBDA_INITIALIZATION_TYPE + */ @Deprecated public static final String ON_DEMAND = "on-demand"; public static final String X_AMZN_TRACE_ID = "_X_AMZN_TRACE_ID"; From b7822035d27972e5623734fe5ad06fb4dd6593ce Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:26:14 +0200 Subject: [PATCH 12/22] fix Constants --- .../amazon/lambda/powertools/idempotency/Constants.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Constants.java b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Constants.java index 28c6f58aa..b527e86a4 100644 --- a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Constants.java +++ b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Constants.java @@ -14,5 +14,10 @@ package software.amazon.lambda.powertools.idempotency; public class Constants { + + private Constants() { + // avoid instantiation, static fields + } + public static final String IDEMPOTENCY_DISABLED_ENV = "POWERTOOLS_IDEMPOTENCY_DISABLED"; } From daf2935e759393e898b84189936c9d8382120993 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:28:34 +0200 Subject: [PATCH 13/22] fix Idempotency --- .../amazon/lambda/powertools/idempotency/Idempotency.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Idempotency.java b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Idempotency.java index ce652791b..dd93373f7 100644 --- a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Idempotency.java +++ b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Idempotency.java @@ -32,14 +32,14 @@ * */ public class Idempotency { - private IdempotencyConfig config; + private IdempotencyConfig idempotencyConfig; private BasePersistenceStore persistenceStore; private Idempotency() { } public IdempotencyConfig getConfig() { - return config; + return idempotencyConfig; } public BasePersistenceStore getPersistenceStore() { @@ -49,8 +49,8 @@ public BasePersistenceStore getPersistenceStore() { return persistenceStore; } - private void setConfig(IdempotencyConfig config) { - this.config = config; + private void setConfig(IdempotencyConfig idempotencyConfig) { + this.idempotencyConfig = idempotencyConfig; } private void setPersistenceStore(BasePersistenceStore persistenceStore) { From b258bcbd7e0bb809f73b14c971a00034cfaba88c Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:31:33 +0200 Subject: [PATCH 14/22] fix IdempotencyHandler --- .../internal/IdempotencyHandler.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/internal/IdempotencyHandler.java b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/internal/IdempotencyHandler.java index 5ce723f04..e9d5e340f 100644 --- a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/internal/IdempotencyHandler.java +++ b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/internal/IdempotencyHandler.java @@ -20,7 +20,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import software.amazon.lambda.powertools.idempotency.Idempotency; -import software.amazon.lambda.powertools.idempotency.exceptions.*; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyAlreadyInProgressException; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyInconsistentStateException; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyItemAlreadyExistsException; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyItemNotFoundException; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyKeyException; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyPersistenceLayerException; +import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyValidationException; import software.amazon.lambda.powertools.idempotency.persistence.BasePersistenceStore; import software.amazon.lambda.powertools.idempotency.persistence.DataRecord; import software.amazon.lambda.powertools.utilities.JsonConfig; @@ -83,9 +89,9 @@ private Object processIdempotency() throws Throwable { // already exists. If it succeeds, there's no need to call getRecord. persistenceStore.saveInProgress(data, Instant.now(), getRemainingTimeInMillis()); } catch (IdempotencyItemAlreadyExistsException iaee) { - DataRecord record = getIdempotencyRecord(); - if (record != null) { - return handleForStatus(record); + DataRecord idempotencyRecord = getIdempotencyRecord(); + if (idempotencyRecord != null) { + return handleForStatus(idempotencyRecord); } } catch (IdempotencyKeyException ike) { throw ike; @@ -132,29 +138,29 @@ private DataRecord getIdempotencyRecord() { /** * Take appropriate action based on data_record's status * - * @param record DataRecord + * @param dataRecord DataRecord * @return Function's response previously used for this idempotency key, if it has successfully executed already. */ - private Object handleForStatus(DataRecord record) { + private Object handleForStatus(DataRecord dataRecord) { // This code path will only be triggered if the record becomes expired between the saveInProgress call and here - if (EXPIRED.equals(record.getStatus())) { + if (EXPIRED.equals(dataRecord.getStatus())) { throw new IdempotencyInconsistentStateException("saveInProgress and getRecord return inconsistent results"); } - if (INPROGRESS.equals(record.getStatus())) { - if (record.getInProgressExpiryTimestamp().isPresent() - && record.getInProgressExpiryTimestamp().getAsLong() < Instant.now().toEpochMilli()) { + if (INPROGRESS.equals(dataRecord.getStatus())) { + if (dataRecord.getInProgressExpiryTimestamp().isPresent() + && dataRecord.getInProgressExpiryTimestamp().getAsLong() < Instant.now().toEpochMilli()) { throw new IdempotencyInconsistentStateException("Item should have been expired in-progress because it already time-outed."); } - throw new IdempotencyAlreadyInProgressException("Execution already in progress with idempotency key: " + record.getIdempotencyKey()); + throw new IdempotencyAlreadyInProgressException("Execution already in progress with idempotency key: " + dataRecord.getIdempotencyKey()); } Class returnType = ((MethodSignature) pjp.getSignature()).getReturnType(); try { - LOG.debug("Response for key '{}' retrieved from idempotency store, skipping the function", record.getIdempotencyKey()); + LOG.debug("Response for key '{}' retrieved from idempotency store, skipping the function", dataRecord.getIdempotencyKey()); if (returnType.equals(String.class)) - return record.getResponseData(); - return JsonConfig.get().getObjectMapper().reader().readValue(record.getResponseData(), returnType); + return dataRecord.getResponseData(); + return JsonConfig.get().getObjectMapper().reader().readValue(dataRecord.getResponseData(), returnType); } catch (Exception e) { throw new IdempotencyPersistenceLayerException("Unable to get function response as " + returnType.getSimpleName(), e); } From 54779c0e1c7c3bf19d6bf750caa04325bdfbb636 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:34:40 +0200 Subject: [PATCH 15/22] fix BasePersistenceStore --- .../persistence/BasePersistenceStore.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/BasePersistenceStore.java b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/BasePersistenceStore.java index c79068d1a..31bda6345 100644 --- a/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/BasePersistenceStore.java +++ b/powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/BasePersistenceStore.java @@ -73,8 +73,8 @@ public abstract class BasePersistenceStore implements PersistenceStore { * @param functionName The name of the function being decorated */ public void configure(IdempotencyConfig config, String functionName) { - String funcEnv = System.getenv(LAMBDA_FUNCTION_NAME_ENV); - this.functionName = funcEnv != null ? funcEnv : "testFunction"; + String functionNameEnv = System.getenv(LAMBDA_FUNCTION_NAME_ENV); + this.functionName = functionNameEnv != null ? functionNameEnv : "testFunction"; if (!StringUtils.isEmpty(functionName)) { this.functionName += "." + functionName; } @@ -123,16 +123,16 @@ public void saveSuccess(JsonNode data, Object result, Instant now) { // missing idempotency key => non-idempotent transaction, we do not store the data, simply return return; } - DataRecord record = new DataRecord( + DataRecord dataRecord = new DataRecord( hashedIdempotencyKey.get(), DataRecord.Status.COMPLETED, getExpiryEpochSecond(now), responseJson, getHashedPayload(data) ); - LOG.debug("Function successfully executed. Saving record to persistence store with idempotency key: {}", record.getIdempotencyKey()); - updateRecord(record); - saveToCache(record); + LOG.debug("Function successfully executed. Saving record to persistence store with idempotency key: {}", dataRecord.getIdempotencyKey()); + updateRecord(dataRecord); + saveToCache(dataRecord); } catch (JsonProcessingException e) { // TODO : throw ? throw new RuntimeException("Error while serializing the response", e); @@ -162,7 +162,7 @@ public void saveInProgress(JsonNode data, Instant now, OptionalInt remainingTime inProgressExpirationMsTimestamp = OptionalLong.of(now.plus(remainingTimeInMs.getAsInt(), ChronoUnit.MILLIS).toEpochMilli()); } - DataRecord record = new DataRecord( + DataRecord dataRecord = new DataRecord( idempotencyKey, DataRecord.Status.INPROGRESS, getExpiryEpochSecond(now), @@ -170,8 +170,8 @@ public void saveInProgress(JsonNode data, Instant now, OptionalInt remainingTime getHashedPayload(data), inProgressExpirationMsTimestamp ); - LOG.debug("saving in progress record for idempotency key: {}", record.getIdempotencyKey()); - putRecord(record, now); + LOG.debug("saving in progress record for idempotency key: {}", dataRecord.getIdempotencyKey()); + putRecord(dataRecord, now); } /** @@ -220,10 +220,10 @@ public DataRecord getRecord(JsonNode data, Instant now) throws IdempotencyValida return cachedRecord; } - DataRecord record = getRecord(idemPotencyKey); - saveToCache(record); - validatePayload(data, record); - return record; + DataRecord dataRecord = getRecord(idemPotencyKey); + saveToCache(dataRecord); + validatePayload(data, dataRecord); + return dataRecord; } /** @@ -368,10 +368,10 @@ private DataRecord retrieveFromCache(String idempotencyKey, Instant now) { if (!useLocalCache) return null; - DataRecord record = cache.get(idempotencyKey); - if (record != null) { - if (!record.isExpired(now)) { - return record; + DataRecord dataRecord = cache.get(idempotencyKey); + if (dataRecord != null) { + if (!dataRecord.isExpired(now)) { + return dataRecord; } LOG.debug("Removing expired local cache record for idempotency key: {}", idempotencyKey); deleteFromCache(idempotencyKey); From 142661cb231b49d61e9f3d347f9126d0300e0d30 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:39:10 +0200 Subject: [PATCH 16/22] fix BaseProvider --- .../amazon/lambda/powertools/parameters/BaseProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/BaseProvider.java b/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/BaseProvider.java index fb539f850..260bd443f 100644 --- a/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/BaseProvider.java +++ b/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/BaseProvider.java @@ -36,7 +36,7 @@ public abstract class BaseProvider implements ParamProvider { private TransformationManager transformationManager; private Clock clock; - public BaseProvider(CacheManager cacheManager) { + protected BaseProvider(CacheManager cacheManager) { this.cacheManager = cacheManager; } From c776fa1b627c22f04922fad968acb2de11ddebde Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:40:59 +0200 Subject: [PATCH 17/22] fix ParamManager --- .../amazon/lambda/powertools/parameters/ParamManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/ParamManager.java b/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/ParamManager.java index c8abedf06..a627c0c91 100644 --- a/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/ParamManager.java +++ b/powertools-parameters/src/main/java/software/amazon/lambda/powertools/parameters/ParamManager.java @@ -35,6 +35,10 @@ public final class ParamManager { // NOTE: For testing purposes `providers` cannot be final private static ConcurrentHashMap, BaseProvider> providers = new ConcurrentHashMap<>(); + private ParamManager() { + // avoid instantiation, static methods + } + /** * Get a concrete implementation of {@link BaseProvider}.
* You can specify {@link SecretsProvider}, {@link SSMProvider} or create your @@ -43,6 +47,7 @@ public final class ParamManager { * @return a {@link SecretsProvider} */ // TODO in v2: remove public access to this and review how we get providers (it was not designed for DDB and AppConfig in mind initially) + @Deprecated public static T getProvider(Class providerClass) { if (providerClass == null) { throw new IllegalStateException("providerClass cannot be null."); From c4e8a2e2f3785b09ea21149f85ff7a4cf646af63 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:43:19 +0200 Subject: [PATCH 18/22] fix EventDeserializer --- .../amazon/lambda/powertools/utilities/EventDeserializer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/EventDeserializer.java b/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/EventDeserializer.java index f1b248fae..0ca938892 100644 --- a/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/EventDeserializer.java +++ b/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/EventDeserializer.java @@ -50,6 +50,10 @@ public class EventDeserializer { private static final Logger LOG = LoggerFactory.getLogger(EventDeserializer.class); + private EventDeserializer() { + // avoid instantiation, static methods + } + /** * Extract the meaningful part of a Lambda Event object. Main events are built-in: *
    From 5f4fc2f16615d015b2cc6e8bd1642ad75cf74ab6 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 18:44:41 +0200 Subject: [PATCH 19/22] fix SqsUtils --- .../amazon/lambda/powertools/sqs/SqsUtils.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java b/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java index 9fff4dc6f..8ecb2ca43 100644 --- a/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java +++ b/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java @@ -13,14 +13,6 @@ */ package software.amazon.lambda.powertools.sqs; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.function.Function; -import java.util.stream.Collectors; - import com.amazonaws.services.lambda.runtime.events.SQSEvent; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -30,8 +22,14 @@ import software.amazon.awssdk.services.sqs.SqsClient; import software.amazon.lambda.powertools.sqs.exception.SkippedMessageDueToFailedBatchException; import software.amazon.lambda.powertools.sqs.internal.BatchContext; -import software.amazon.payloadoffloading.PayloadS3Pointer; import software.amazon.lambda.powertools.sqs.internal.SqsLargeMessageAspect; +import software.amazon.payloadoffloading.PayloadS3Pointer; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage; import static software.amazon.lambda.powertools.sqs.internal.SqsLargeMessageAspect.processMessages; @@ -556,7 +554,6 @@ private static SqsMessageHandler instantiatedHandler(final Class Date: Tue, 25 Jul 2023 18:45:44 +0200 Subject: [PATCH 20/22] fix BatchContext --- .../powertools/sqs/internal/BatchContext.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/internal/BatchContext.java b/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/internal/BatchContext.java index 1e4eff3bf..69bf29faa 100644 --- a/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/internal/BatchContext.java +++ b/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/internal/BatchContext.java @@ -1,14 +1,5 @@ package software.amazon.lambda.powertools.sqs.internal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.IntStream; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import org.slf4j.Logger; @@ -28,8 +19,17 @@ import software.amazon.lambda.powertools.sqs.SQSBatchProcessingException; import software.amazon.lambda.powertools.sqs.SqsUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage; -import static java.lang.String.format; import static java.util.Optional.ofNullable; import static java.util.stream.Collectors.toList; @@ -114,8 +114,8 @@ private void processFailedMessages(List successReturns, map(SQSMessage::getMessageId) .collect(toList()); - LOG.debug(format("[%d] records failed processing, but exceptions are suppressed. " + - "Failed messages %s", failedMessages.size(), messageIds)); + LOG.debug("[{}] records failed processing, but exceptions are suppressed. " + + "Failed messages {}", failedMessages.size(), messageIds); } else { throw new SQSBatchProcessingException(exceptions, failedMessages, successReturns); } From 505fdbc2aa1953a0ffa18e1169c21f4f18939db2 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 21:00:13 +0200 Subject: [PATCH 21/22] fix AbstractCustomResourceHandler --- .../src/main/java/helloworld/App.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java b/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java index a5763a522..754036c94 100644 --- a/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java +++ b/examples/powertools-examples-cloudformation/src/main/java/helloworld/App.java @@ -26,8 +26,8 @@ public class App extends AbstractCustomResourceHandler { private final static Logger log = LogManager.getLogger(App.class); - public static final String CFN_CUSTOM_RESOURCE_EVENT_CANNOT_BE_NULL = "cloudFormationCustomResourceEvent cannot be null."; - public static final String BUCKET_NAME = "BucketName"; + private static final String CFN_CUSTOM_RESOURCE_EVENT_CANNOT_BE_NULL = "cloudFormationCustomResourceEvent cannot be null."; + private static final String BUCKET_NAME = "BucketName"; private final S3Client s3Client; public App() { From 97a553f5689fee4f5f8a3ce7d96badc4f16d96fa Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Tue, 25 Jul 2023 21:14:01 +0200 Subject: [PATCH 22/22] rename getAdditionalFields which already exist... --- .../lambda/powertools/logging/internal/LambdaJsonLayout.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java index 676e6ed82..c49ac7af0 100644 --- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java +++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java @@ -187,7 +187,7 @@ public static LambdaJsonLayout createDefaultLayout() { @Override public Object wrapLogEvent(final LogEvent event) { - Map additionalFieldsMap = getAdditionalFields(event); + Map additionalFieldsMap = retrieveAdditionalFields(event); // This class combines LogEvent with AdditionalFields during serialization return new LogEventWithAdditionalFields(event, additionalFieldsMap); } @@ -200,7 +200,7 @@ public void toSerializable(final LogEvent event, final Writer writer) throws IOE super.toSerializable(event, writer); } - private Map getAdditionalFields(LogEvent logEvent) { + private Map retrieveAdditionalFields(LogEvent logEvent) { // Note: LinkedHashMap retains order final Map additionalFieldsMap = new LinkedHashMap<>(additionalFields.length);