Skip to content
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
2 changes: 1 addition & 1 deletion examples/powertools-examples-batch/deploy/sqs/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Resources:
DemoSQSSenderFunction:
Type: AWS::Serverless::Function
Properties:
Tracing: Active
CodeUri: ../..
Handler: org.demo.batch.sqs.SqsBatchSender::handleRequest
Environment:
Expand Down Expand Up @@ -173,7 +174,6 @@ Resources:
Action:
- s3:PutObject
Resource: !Sub ${Bucket.Arn}/*

Events:
MySQSEvent:
Type: SQS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@

package org.demo.batch.sqs;

import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;

import org.demo.batch.model.Product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.fasterxml.jackson.databind.ObjectMapper;

import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.tracing.Tracing;
import software.amazon.lambda.powertools.tracing.TracingUtils;

Expand All @@ -43,23 +44,23 @@ public class AbstractSqsBatchHandler {
* Simulate some processing (I/O + S3 put request)
* @param p deserialized product
*/
@Logging
@Tracing
protected void processMessage(Product p) {
TracingUtils.putAnnotation("productId", p.getId());
TracingUtils.putAnnotation("Thread", Thread.currentThread().getName());
MDC.put("product", String.valueOf(p.getId()));
LOGGER.info("Processing product {}", p);

char c = (char)(r.nextInt(26) + 'a');
char c = (char) (r.nextInt(26) + 'a');
char[] chars = new char[1024 * 1000];
Arrays.fill(chars, c);
p.setName(new String(chars));
try {
File file = new File("/tmp/"+p.getId()+".json");
File file = new File("/tmp/" + p.getId() + ".json");
mapper.writeValue(file, p);
s3.putObject(
PutObjectRequest.builder().bucket(bucket).key(p.getId()+".json").build(), RequestBody.fromFile(file));
PutObjectRequest.builder().bucket(bucket).key(p.getId() + ".json").build(),
RequestBody.fromFile(file));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
Expand Down
Loading