Skip to content

Commit 0db9322

Browse files
authored
Merge pull request #2 from localstack/app-enhancements
-small adjustments
2 parents 646e4f1 + 2072f7b commit 0db9322

File tree

9 files changed

+22
-491
lines changed

9 files changed

+22
-491
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- "127.0.0.1:4566:4566" # LocalStack Gateway
99
- "127.0.0.1:4510-4559:4510-4559" # external services port range
1010
environment:
11-
# - DEBUG=1 # enable more verbose logs
11+
- DEBUG=1 # enable more verbose logs
1212
- DOCKER_HOST=unix:///var/run/docker.sock #unix socket to communicate with the docker daemon
1313
# - LAMBDA_KEEPALIVE_MS=0 # disable lambda keepalive
1414
- LOCALSTACK_HOST=localstack # where services are available from other containers

setup/terraform/main.tf

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ provider "aws" {
1010
region = "eu-central-1"
1111
}
1212

13+
# S3 bucket
1314
resource "aws_s3_bucket" "shipment_picture_bucket" {
1415
bucket = "shipment-picture-bucket"
1516
force_destroy = true
@@ -18,6 +19,7 @@ resource "aws_s3_bucket" "shipment_picture_bucket" {
1819
}
1920
}
2021

22+
# DynamoDB table creation
2123
resource "aws_dynamodb_table" "shipment" {
2224
name = "shipment"
2325
read_capacity = 10
@@ -36,14 +38,15 @@ resource "aws_dynamodb_table" "shipment" {
3638
stream_view_type = "NEW_AND_OLD_IMAGES"
3739
}
3840

41+
# Populate the table
3942
resource "aws_dynamodb_table_item" "shipment" {
4043
for_each = local.tf_data
4144
table_name = aws_dynamodb_table.shipment.name
4245
hash_key = "shipmentId"
4346
item = jsonencode(each.value)
4447
}
4548

46-
49+
# Define a bucket for the lambda zip
4750
resource "aws_s3_bucket" "lambda_code_bucket" {
4851
bucket = "shipment-picture-lambda-validator-bucket"
4952
force_destroy = true
@@ -52,12 +55,14 @@ resource "aws_s3_bucket" "lambda_code_bucket" {
5255
}
5356
}
5457

58+
# Lambda source code
5559
resource "aws_s3_bucket_object" "lambda_code" {
5660
source = "../../shipment-picture-lambda-validator/target/shipment-picture-lambda-validator.jar"
5761
bucket = aws_s3_bucket.lambda_code_bucket.id
5862
key = "shipment-picture-lambda-validator.jar"
5963
}
6064

65+
# Lambda definition
6166
resource "aws_lambda_function" "shipment_picture_lambda_validator" {
6267
function_name = "shipment-picture-lambda-validator"
6368
handler = "dev.ancaghenade.shipmentpicturelambdavalidator.ServiceHandler::handleRequest"
@@ -74,6 +79,7 @@ resource "aws_lambda_function" "shipment_picture_lambda_validator" {
7479
}
7580
}
7681

82+
# Define trigger for S3
7783
resource "aws_s3_bucket_notification" "demo_bucket_notification" {
7884
bucket = aws_s3_bucket.shipment_picture_bucket.id
7985
lambda_function {
@@ -82,6 +88,7 @@ resource "aws_s3_bucket_notification" "demo_bucket_notification" {
8288
}
8389
}
8490

91+
# Give Lambda permission to call S3
8592
resource "aws_lambda_permission" "s3_lambda_exec_permission" {
8693
statement_id = "AllowExecutionFromS3Bucket"
8794
action = "lambda:InvokeFunction"
@@ -90,7 +97,7 @@ resource "aws_lambda_permission" "s3_lambda_exec_permission" {
9097
source_arn = aws_s3_bucket.shipment_picture_bucket.arn
9198
}
9299

93-
100+
# Define role to execute Lambda
94101
resource "aws_iam_role" "lambda_exec" {
95102
name = "lambda_exec_role"
96103

@@ -110,12 +117,14 @@ resource "aws_iam_role" "lambda_exec" {
110117
EOF
111118
}
112119

120+
121+
# Attach policy (S3 access) to Lambda role
113122
resource "aws_iam_role_policy_attachment" "lambda_exec_policy" {
114123
policy_arn = "arn:aws:iam::aws:policy/AmazonS3FullAccess"
115124
role = aws_iam_role.lambda_exec.name
116125
}
117126

118-
127+
# Define IAM role policy that grants permissions to access & process on AWS CloudWatch Logs, S3
119128
resource "aws_iam_role_policy" "lambda_exec_policy" {
120129
name = "lambda_exec_policy"
121130
role = aws_iam_role.lambda_exec.id
@@ -151,20 +160,25 @@ resource "aws_iam_role_policy" "lambda_exec_policy" {
151160
EOF
152161
}
153162

163+
# Define the topic
154164
resource "aws_sns_topic" "update_shipment_picture_topic" {
155165
name = "update_shipment_picture_topic"
156166
}
157167

168+
# Define the queue
158169
resource "aws_sqs_queue" "update_shipment_picture_queue" {
159170
name = "update_shipment_picture_queue"
160171
}
161172

173+
# Define subscription
162174
resource "aws_sns_topic_subscription" "my_subscription" {
163175
topic_arn = aws_sns_topic.update_shipment_picture_topic.arn
164176
protocol = "sqs"
165177
endpoint = aws_sqs_queue.update_shipment_picture_queue.arn
166178
}
167179

180+
181+
# Define policy to allow SNS to send message to SQS
168182
resource "aws_sqs_queue_policy" "my_queue_policy" {
169183
queue_url = aws_sqs_queue.update_shipment_picture_queue.id
170184

@@ -189,13 +203,14 @@ resource "aws_sqs_queue_policy" "my_queue_policy" {
189203
EOF
190204
}
191205

206+
# Define the SQS subscription
192207
resource "aws_sns_topic_subscription" "my_topic_subscription" {
193208
topic_arn = aws_sns_topic.update_shipment_picture_topic.arn
194209
protocol = "sqs"
195210
endpoint = aws_sqs_queue.update_shipment_picture_queue.arn
196211

197212
# Additional subscription attributes
198-
raw_message_delivery = true
213+
# raw_message_delivery = true
199214
filter_policy = ""
200215
delivery_policy = ""
201216

setup/tflocal/data.json

Lines changed: 0 additions & 254 deletions
This file was deleted.

0 commit comments

Comments
 (0)