Skip to content

Commit d2719fd

Browse files
committed
Clean up s3-java code example
- Remove unnecessary imports and lines - Remove gson dependency; example still works as before
1 parent 0bc6c12 commit d2719fd

File tree

5 files changed

+1
-26
lines changed

5 files changed

+1
-26
lines changed

sample-apps/s3-java/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ To invoke the function directly, run `5-invoke.sh`.
7979
"ExecutedVersion": "$LATEST"
8080
}
8181

82-
Let the script invoke the function a few times and then press `CRTL+C` to exit. Note that you
83-
may see function timeouts in the first few iterations due to cold starts; after a while, they
84-
should begin to succeed.
82+
Let the script invoke the function a few times and then press `CRTL+C` to exit.
8583

8684
If you look at the `s3-java-bucket-<random_uuid>` bucket in your account, you should now see a
8785
key `resized-inbound/sample-s3-java.png` file, which represents the new, shrunken image.

sample-apps/s3-java/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies {
1919
implementation 'com.amazonaws:aws-xray-recorder-sdk-core'
2020
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk'
2121
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-instrumentor'
22-
implementation 'com.google.code.gson:gson:2.8.6'
2322
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
2423
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
2524
}

sample-apps/s3-java/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@
7878
<groupId>com.amazonaws</groupId>
7979
<artifactId>aws-xray-recorder-sdk-aws-sdk-instrumentor</artifactId>
8080
</dependency>
81-
<dependency>
82-
<groupId>com.google.code.gson</groupId>
83-
<artifactId>gson</artifactId>
84-
<version>2.8.6</version>
85-
</dependency>
8681
<dependency>
8782
<groupId>org.junit.jupiter</groupId>
8883
<artifactId>junit-jupiter-api</artifactId>

sample-apps/s3-java/src/main/java/example/Handler.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.awt.Graphics2D;
55
import java.awt.RenderingHints;
66
import java.awt.image.BufferedImage;
7-
import java.io.ByteArrayInputStream;
87
import java.io.ByteArrayOutputStream;
98
import java.io.IOException;
109
import java.io.InputStream;
@@ -19,23 +18,18 @@
1918
import software.amazon.awssdk.core.sync.RequestBody;
2019
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
2120
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
22-
import software.amazon.awssdk.services.s3.model.S3Object;
2321
import software.amazon.awssdk.services.s3.S3Client;
2422

2523
import com.amazonaws.services.lambda.runtime.Context;
2624
import com.amazonaws.services.lambda.runtime.RequestHandler;
2725
import com.amazonaws.services.lambda.runtime.events.S3Event;
2826
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.S3EventNotificationRecord;
2927

30-
import com.google.gson.Gson;
31-
import com.google.gson.GsonBuilder;
32-
3328
import org.slf4j.Logger;
3429
import org.slf4j.LoggerFactory;
3530

3631
// Handler value: example.Handler
3732
public class Handler implements RequestHandler<S3Event, String> {
38-
Gson gson = new GsonBuilder().setPrettyPrinting().create();
3933
private static final Logger logger = LoggerFactory.getLogger(Handler.class);
4034
private static final float MAX_DIMENSION = 100;
4135
private final String REGEX = ".*\\.([^\\.]*)";
@@ -46,7 +40,6 @@ public class Handler implements RequestHandler<S3Event, String> {
4640
@Override
4741
public String handleRequest(S3Event s3event, Context context) {
4842
try {
49-
logger.info("EVENT: " + gson.toJson(s3event));
5043
S3EventNotificationRecord record = s3event.getRecords().get(0);
5144

5245
String srcBucket = record.getS3().getBucket().getName();

sample-apps/s3-java/src/test/java/example/InvokeTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package example;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
43
import static org.junit.jupiter.api.Assertions.assertTrue;
54
import org.junit.jupiter.api.Test;
65

76
import com.amazonaws.services.lambda.runtime.Context;
8-
import com.amazonaws.services.lambda.runtime.LambdaLogger;
9-
import com.amazonaws.services.lambda.runtime.RequestHandler;
107
import com.amazonaws.services.lambda.runtime.events.S3Event;
11-
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification;
128
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.RequestParametersEntity;
139
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.ResponseElementsEntity;
1410
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.S3BucketEntity;
@@ -17,10 +13,6 @@
1713
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.S3ObjectEntity;
1814
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.UserIdentityEntity;
1915

20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
22-
23-
import java.util.List;
2416
import java.util.ArrayList;
2517
import java.lang.Long;
2618
import java.nio.file.Files;
@@ -32,7 +24,6 @@
3224
import com.amazonaws.xray.strategy.sampling.NoSamplingStrategy;
3325

3426
class InvokeTest {
35-
private static final Logger logger = LoggerFactory.getLogger(InvokeTest.class);
3627

3728
public InvokeTest() {
3829
AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard();
@@ -67,7 +58,6 @@ void invokeTest() throws IOException {
6758
S3Event event = new S3Event(records);
6859

6960
Context context = new TestContext();
70-
String requestId = context.getAwsRequestId();
7161
Handler handler = new Handler();
7262
String result = handler.handleRequest(event, context);
7363
assertTrue(result.contains("Ok"));

0 commit comments

Comments
 (0)