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.
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

src/main/resources/buckets.properties

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

terraform/locals.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
locals {
22
json_data = file("./data.json")
33
tf_data = jsondecode(local.json_data)
4+
sns_topic_arn_prod = "arn:aws:sns:${var.aws_region}:${var.account_id}:${var.sns_topic_name}"
5+
sns_topic_arn_dev = "arn:aws:sns:${var.aws_region}:000000000000:${var.sns_topic_name}"
46
}

terraform/main.tf

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "= 4.66.1"
5+
version = "= 5.31.0"
66
}
77
}
88
}
@@ -19,6 +19,21 @@ resource "random_pet" "random_name" {
1919
separator = "-"
2020
}
2121

22+
variable "aws_region" {
23+
description = "AWS region"
24+
default = "us-east-1"
25+
}
26+
27+
variable "account_id" {
28+
description = "AWS Account ID"
29+
default = "YOUR_AWS_ACCOUNT_NUMBER"
30+
}
31+
32+
variable "sns_topic_name" {
33+
description = "SNS Topic Name"
34+
default = "update_shipment_picture_topic"
35+
}
36+
2237
# S3 bucket
2338
resource "aws_s3_bucket" "shipment_picture_bucket" {
2439
bucket = "shipment-picture-bucket-${random_pet.random_name.id}"
@@ -75,7 +90,7 @@ resource "aws_s3_bucket_object" "lambda_code" {
7590
resource "aws_lambda_function" "shipment_picture_lambda_validator" {
7691
function_name = "shipment-picture-lambda-validator"
7792
handler = "dev.ancaghenade.shipmentpicturelambdavalidator.ServiceHandler::handleRequest"
78-
runtime = "java11"
93+
runtime = "java17"
7994
role = aws_iam_role.lambda_exec.arn
8095
s3_bucket = aws_s3_bucket.lambda_code_bucket.id
8196
s3_key = aws_s3_bucket_object.lambda_code.key
@@ -84,6 +99,8 @@ resource "aws_lambda_function" "shipment_picture_lambda_validator" {
8499
environment {
85100
variables = {
86101
BUCKET = aws_s3_bucket.shipment_picture_bucket.bucket
102+
SNS_TOPIC_ARN_DEV = local.sns_topic_arn_dev
103+
SNS_TOPIC_ARN_PROD = local.sns_topic_arn_prod
87104
}
88105
}
89106
}
@@ -171,7 +188,7 @@ resource "aws_iam_role_policy" "lambda_exec_policy" {
171188

172189
# Define the topic
173190
resource "aws_sns_topic" "update_shipment_picture_topic" {
174-
name = "update_shipment_picture_topic"
191+
name = "${var.sns_topic_name}"
175192
}
176193

177194
# Define the queue

0 commit comments

Comments
 (0)