Skip to content

Commit b146266

Browse files
authored
Merge pull request #6 from localstack-samples/app_updates
App updates
2 parents c14a14d + 33d39f9 commit b146266

File tree

12 files changed

+58
-77
lines changed

12 files changed

+58
-77
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ services:
1010
environment:
1111
- DEBUG=1 # enable more verbose logs
1212
- DOCKER_HOST=unix:///var/run/docker.sock #unix socket to communicate with the docker daemon
13-
# - LAMBDA_KEEPALIVE_MS=0 # disable lambda keepalive
1413
- LOCALSTACK_HOST=localstack # where services are available from other containers
1514
- ENFORCE_IAM=1 # enforce IAM policies
15+
# - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN}
1616
volumes:
1717
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
1818
- "/var/run/docker.sock:/var/run/docker.sock"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<dependency>
8383
<groupId>software.amazon.awssdk</groupId>
8484
<artifactId>bom</artifactId>
85-
<version>2.20.26</version>
85+
<version>2.22.12</version>
8686
<type>pom</type>
8787
<scope>import</scope>
8888
</dependency>

shipment-list-demo-cloud-pod

39.9 MB
Binary file not shown.

shipment-picture-lambda-validator/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<version>1.0-SNAPSHOT</version>
1010

1111
<properties>
12-
<maven.compiler.source>11</maven.compiler.source>
13-
<maven.compiler.target>11</maven.compiler.target>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
1414
</properties>
1515

1616
<dependencies>
@@ -21,7 +21,6 @@
2121
<dependency>
2222
<groupId>software.amazon.awssdk</groupId>
2323
<artifactId>protocol-core</artifactId>
24-
<version>2.20.47</version>
2524
</dependency>
2625
<dependency>
2726
<groupId>software.amazon.awssdk</groupId>
@@ -68,7 +67,7 @@
6867
<dependency>
6968
<groupId>software.amazon.awssdk</groupId>
7069
<artifactId>bom</artifactId>
71-
<version>2.20.47</version>
70+
<version>2.22.12</version>
7271
<type>pom</type>
7372
<scope>import</scope>
7473
</dependency>

shipment-picture-lambda-validator/src/main/java/dev/ancaghenade/shipmentpicturelambdavalidator/Location.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55

66
@Getter
77
public enum Location {
8+
REGION(Region.US_EAST_1);
9+
private final Region region;
810

9-
10-
REGION(Region.US_EAST_1);
11-
12-
private final Region region;
13-
Location(Region region) {
14-
this.region = region;
15-
}
11+
Location(Region region) {
12+
this.region = region;
13+
}
1614
}

shipment-picture-lambda-validator/src/main/java/dev/ancaghenade/shipmentpicturelambdavalidator/PropertiesProvider.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
package dev.ancaghenade.shipmentpicturelambdavalidator;
22

3+
import software.amazon.awssdk.services.sns.SnsClient;
4+
35
import java.net.URI;
46
import java.util.Objects;
5-
import software.amazon.awssdk.services.sns.SnsClient;
67

78
public class SNSClientHelper {
89

9-
private static final String AWS_ENDPOINT_URL = System.getenv("AWS_ENDPOINT_URL");
10-
private static String snsTopicArn;
10+
private static final String AWS_ENDPOINT_URL = System.getenv("AWS_ENDPOINT_URL");
11+
private static String snsTopicArn;
1112

12-
public static SnsClient getSnsClient() {
13+
public static SnsClient getSnsClient() {
1314

14-
var clientBuilder = SnsClient.builder();
15+
var clientBuilder = SnsClient.builder();
1516

16-
if (Objects.nonNull(AWS_ENDPOINT_URL)) {
17-
snsTopicArn = String.format("arn:aws:sns:%s:000000000000:update_shipment_picture_topic",
18-
Location.REGION.getRegion());
17+
if (Objects.nonNull(AWS_ENDPOINT_URL)) {
18+
snsTopicArn = System.getenv("SNS_TOPIC_ARN_DEV");
1919

20-
return clientBuilder
21-
.region(Location.REGION.getRegion())
22-
.endpointOverride(URI.create(AWS_ENDPOINT_URL))
23-
.build();
24-
} else {
25-
snsTopicArn = String.format("arn:aws:sns:%s:%s:update_shipment_picture_topic",
26-
Location.REGION.getRegion(), "932043840972");
27-
return clientBuilder.build();
20+
return clientBuilder
21+
.region(Location.REGION.getRegion())
22+
.endpointOverride(URI.create(AWS_ENDPOINT_URL))
23+
.build();
24+
} else {
25+
snsTopicArn = System.getenv("SNS_TOPIC_ARN_PROD");
26+
return clientBuilder.build();
27+
}
28+
}
29+
public static String topicARN() {
30+
return snsTopicArn;
2831
}
29-
}
30-
31-
public static String topicARN() {
32-
return snsTopicArn;
33-
}
3432

3533
}

shipment-picture-lambda-validator/src/main/java/dev/ancaghenade/shipmentpicturelambdavalidator/ServiceHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream,
6464

6565
// Check if the image was already processed
6666
if (s3ObjectResponse.response().metadata().entrySet().stream().anyMatch(
67-
entry -> entry.getKey().equals("exclude-lambda") && entry.getValue().equals("true"))) {
67+
entry -> entry.getKey().equals("skip-processing") && entry.getValue().equals("true"))) {
6868
context.getLogger().log("Object already present.");
6969
return;
7070
}
@@ -98,7 +98,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream,
9898
var putObjectRequest = PutObjectRequest.builder()
9999
.bucket(BUCKET_NAME)
100100
.key(objectKey)
101-
.metadata(Collections.singletonMap("exclude-lambda", "true"))
101+
.metadata(Collections.singletonMap("skip-processing", "true"))
102102
.build();
103103

104104
s3Client.putObject(putObjectRequest, RequestBody.fromBytes(imageBytes));
@@ -114,7 +114,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream,
114114
var putObjectRequest = PutObjectRequest.builder()
115115
.bucket(BUCKET_NAME)
116116
.key(objectKey)
117-
.metadata(Collections.singletonMap("exclude-lambda", "true"))
117+
.metadata(Collections.singletonMap("skip-processing", "true"))
118118
.build();
119119

120120
s3Client.putObject(putObjectRequest, RequestBody.fromBytes(
@@ -143,7 +143,7 @@ private String getObjectKey(InputStream inputStream, Context context) {
143143
return keys.iterator().next();
144144
}
145145
} catch (IOException ioe) {
146-
context.getLogger().log("caught IOException reading input stream");
146+
context.getLogger().log("caught IOException reading input stream: " + ioe.getMessage());
147147
}
148148
return null;
149149
}

src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ aws:
77
dynamodb:
88
endpoint: http://localhost.localstack.cloud:4566/
99
sqs:
10-
endpoint: http://localhost:4566/000000000000
10+
endpoint: http://localhost.localstack.cloud:4566/000000000000
1111
region: us-east-1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
shipment-picture-bucket=shipment-picture-bucket-concise-malamute
2-
shipment-picture-bucket-validator=shipment-picture-lambda-validator-bucket-concise-malamute
1+
shipment-picture-bucket=shipment-picture-bucket-certain-yak
2+
shipment-picture-bucket-validator=shipment-picture-lambda-validator-bucket-certain-yak

0 commit comments

Comments
 (0)