Skip to content

Commit 5f8ec0c

Browse files
committed
Initial code
1 parent 2836c5b commit 5f8ec0c

7 files changed

Lines changed: 166 additions & 161 deletions

File tree

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
{
2-
"folders": [
3-
{
4-
"path": "."
5-
},
6-
{
7-
"path": "backend"
8-
},
9-
{
10-
"path": "filenameprocessor"
11-
},
12-
{
13-
"path": "recordprocessor"
14-
},
15-
{
16-
"path": "ack_backend"
17-
},
18-
{
19-
"path": "delta_backend"
20-
},
21-
{
22-
"path": "mesh_processor"
23-
}
24-
],
25-
"settings": {},
26-
}
2+
"folders": [
3+
{
4+
"path": "."
5+
},
6+
{
7+
"path": "backend"
8+
},
9+
{
10+
"path": "filenameprocessor"
11+
},
12+
{
13+
"path": "recordprocessor"
14+
},
15+
{
16+
"path": "ack_backend"
17+
},
18+
{
19+
"path": "delta_backend"
20+
},
21+
{
22+
"path": "mesh_processor"
23+
},
24+
{
25+
"path": "redis_sync"
26+
}
27+
],
28+
"settings": {}
29+
}

redis_sync/README.md

Whitespace-only changes.

redis_sync/poetry.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

redis_sync/pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[project]
2+
name = "redis-sync"
3+
version = "0.1.0"
4+
description = "Sync s3 to REDIS"
5+
authors = [
6+
{name = "nhsdevws",email = "stephen.wates1@nhs.net"}
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.11"
10+
dependencies = [
11+
]
12+
13+
14+
[build-system]
15+
requires = ["poetry-core>=2.0.0,<3.0.0"]
16+
build-backend = "poetry.core.masonry.api"

redis_sync/src/redis_sync.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# handler to do redis sync from s3
2+
3+
def sync_handler(event, context):
4+
print("Redis sync handler invoked with event")

terraform/redis_sync_lambda.tf

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
locals {
2+
redis_sync_dir = abspath("${path.root}/../redis_sync")
3+
redis_sync_files = fileset(local.redis_sync_dir, "**")
4+
redis_sync_dir_sha = sha1(join("", [for f in local.redis_sync_files : filesha1("${local.redis_sync_dir}/${f}")]))
5+
function_name = "redis_sync"
6+
dlq_name = "redis_sync-dlq"
7+
sns_name = "redis_sync-sns"
8+
}
9+
10+
resource "aws_iam_role" "redis_sync_lambda_role" {
11+
name = "${local.short_prefix}-${local.function_name}-role"
12+
assume_role_policy = <<EOF
13+
{
14+
"Version": "2012-10-17",
15+
"Statement": [
16+
{
17+
"Action": "sts:AssumeRole",
18+
"Principal": {
19+
"Service": "lambda.amazonaws.com"
20+
},
21+
"Effect": "Allow",
22+
"Sid": ""
23+
}
24+
]
25+
}
26+
EOF
27+
}
28+
29+
resource "aws_iam_role_policy" "redis_sync_lambda_role_policy" {
30+
name = "${local.prefix}-${local.function_name}-policy"
31+
role = aws_iam_role.redis_sync_lambda_role.id
32+
policy = data.aws_iam_policy_document.redis_sync_policy_document.json
33+
}
34+
35+
data "archive_file" "redis_sync_lambda_zip" {
36+
type = "zip"
37+
source_dir = local.redis_sync_dir
38+
output_path = "${path.module}/build/redis_sync_lambda.zip"
39+
}
40+
41+
resource "aws_lambda_function" "redis_sync_lambda" {
42+
function_name = "${local.short_prefix}-${local.function_name}"
43+
role = aws_iam_role.redis_sync_lambda_role.arn
44+
handler = "redis_sync.sync_handler" # Update as appropriate
45+
runtime = "python3.11"
46+
filename = data.archive_file.redis_sync_lambda_zip.output_path
47+
source_code_hash = data.archive_file.redis_sync_lambda_zip.output_base64sha256
48+
architectures = ["x86_64"]
49+
50+
environment {
51+
variables = {
52+
DELTA_TABLE_NAME = aws_dynamodb_table.delta-dynamodb-table.name
53+
AWS_SQS_QUEUE_URL = aws_sqs_queue.dlq.id
54+
SOURCE = "IEDS"
55+
SPLUNK_FIREHOSE_NAME = module.splunk.firehose_stream_name
56+
}
57+
}
58+
59+
depends_on = [
60+
aws_cloudwatch_log_group.redis_sync_lambda
61+
]
62+
}
63+
64+
resource "aws_cloudwatch_log_group" "redis_sync_lambda" {
65+
name = "/aws/lambda/${local.short_prefix}-${local.function_name}"
66+
retention_in_days = 30
67+
}
68+
69+
resource "aws_lambda_event_source_mapping" "redis_sync_trigger" {
70+
event_source_arn = aws_dynamodb_table.events-dynamodb-table.stream_arn
71+
function_name = aws_lambda_function.redis_sync_lambda.function_name
72+
starting_position = "TRIM_HORIZON"
73+
destination_config {
74+
on_failure {
75+
destination_arn = aws_sns_topic.redis_sync_sns.arn
76+
}
77+
}
78+
maximum_retry_attempts = 0
79+
}
80+
81+
resource "aws_sqs_queue" "dlq" {
82+
name = "${local.short_prefix}-${local.dlq_name}"
83+
}
84+
85+
resource "aws_sns_topic" "redis_sync_sns" {
86+
name = "${local.short_prefix}-${local.sns_name}"
87+
}
88+
89+
data "aws_iam_policy_document" "redis_sync_policy_document" {
90+
source_policy_documents = [
91+
templatefile("${local.policy_path}/dynamodb.json", {
92+
"dynamodb_table_name" : aws_dynamodb_table.delta-dynamodb-table.name
93+
}),
94+
templatefile("${local.policy_path}/dynamodb_stream.json", {
95+
"dynamodb_table_name" : aws_dynamodb_table.events-dynamodb-table.name
96+
}),
97+
templatefile("${local.policy_path}/aws_sqs_queue.json", {
98+
"aws_sqs_queue_name" : aws_sqs_queue.dlq.name
99+
}),
100+
templatefile("${local.policy_path}/dynamo_key_access.json", {
101+
"dynamo_encryption_key" : data.aws_kms_key.existing_dynamo_encryption_key.arn
102+
}),
103+
templatefile("${local.policy_path}/aws_sns_topic.json", {
104+
"aws_sns_topic_name" : aws_sns_topic.redis_sync_sns.name
105+
}),
106+
templatefile("${local.policy_path}/log_kinesis.json", {
107+
"kinesis_stream_name" : module.splunk.firehose_stream_name
108+
}),
109+
templatefile("${local.policy_path}/log.json", {}),
110+
]
111+
}

terraform/temp.tf

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

0 commit comments

Comments
 (0)