Skip to content

Commit 73b1820

Browse files
author
Pankaj Agrawal
committed
fix: lazy load sqs client
1 parent 3fd8bb5 commit 73b1820

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public Object around(ProceedingJoinPoint pjp,
8686

8787
setLogLevelBasedOnSamplingRate(pjp, logging);
8888

89-
Context extractContext = extractContext(pjp);
89+
Context extractedContext = extractContext(pjp);
9090

91-
if(null != extractContext) {
92-
appendKeys(DefaultLambdaFields.values(extractContext));
91+
if(null != extractedContext) {
92+
appendKeys(DefaultLambdaFields.values(extractedContext));
9393
appendKey("coldStart", isColdStart() ? "true" : "false");
9494
appendKey("service", serviceName());
9595
}

powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public Object around(ProceedingJoinPoint pjp,
5454

5555
logger.setNamespace(namespace(metrics));
5656

57-
Context extractContext = extractContext(pjp);
57+
Context extractedContext = extractContext(pjp);
5858

59-
if( null != extractContext) {
60-
coldStartSingleMetricIfApplicable(extractContext.getAwsRequestId(), extractContext.getFunctionName(), metrics);
61-
logger.putProperty(REQUEST_ID_PROPERTY, extractContext.getAwsRequestId());
59+
if( null != extractedContext) {
60+
coldStartSingleMetricIfApplicable(extractedContext.getAwsRequestId(), extractedContext.getFunctionName(), metrics);
61+
logger.putProperty(REQUEST_ID_PROPERTY, extractedContext.getAwsRequestId());
6262
}
6363

6464
LambdaHandlerProcessor.getXrayTraceId()

powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class SqsUtils {
4141
private static final Logger LOG = LoggerFactory.getLogger(SqsUtils.class);
4242

4343
private static final ObjectMapper objectMapper = new ObjectMapper();
44-
private static SqsClient client = SqsClient.create();
44+
private static SqsClient client;
4545

4646
private SqsUtils() {
4747
}
@@ -231,6 +231,10 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
231231
final SqsMessageHandler<R> handler) {
232232
final List<R> handlerReturn = new ArrayList<>();
233233

234+
if(client == null) {
235+
client = SqsClient.create();
236+
}
237+
234238
BatchContext batchContext = new BatchContext(client);
235239

236240
for (SQSMessage message : event.getRecords()) {

0 commit comments

Comments
 (0)