Skip to content

Commit 8ea1ff7

Browse files
committed
#4 Source configs from S3
1 parent ed7dfc0 commit 8ea1ff7

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

Conf/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"accessConfig": "conf/access.json",
3-
"topicsConfig": "conf/topics.json",
2+
"accessConfig": "s3://<redacted>/access.json",
3+
"topicsConfig": "s3://<redacted>/topics.json",
44
"tokenProviderUrl": "https://<redacted>",
55
"tokenPublicKeyUrl": "https://<redacted>",
66
"kafkaBootstrapServer": "localhost:9092"

Src/event_gate_lambda.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,35 @@
2424
import jwt
2525
import requests
2626

27+
import boto3
2728
from confluent_kafka import Producer
2829

2930
with open("conf/config.json", "r") as file:
3031
CONFIG = json.load(file)
3132

32-
with open(CONFIG["topicsConfig"], "r") as file:
33-
TOPICS = json.load(file)
33+
aws_session = boto3.Session()
34+
aws_s3 = aws_session.resource('s3', verify=False)
3435

35-
with open(CONFIG["accessConfig"], "r") as file:
36-
ACCESS = json.load(file)
36+
if CONFIG["topicsConfig"].startswith("s3://"):
37+
name_parts = CONFIG["topicsConfig"].split('/')
38+
bucket_name = name_parts[2]
39+
bucket_object = "/".join(name_parts[3:])
40+
TOPICS = json.loads(aws_s3.Bucket(bucket_name).Object(bucket_object).get()["Body"].read().decode("utf-8"))
41+
else:
42+
with open(CONFIG["topicsConfig"], "r") as file:
43+
TOPICS = json.load(file)
44+
45+
if CONFIG["accessConfig"].startswith("s3://"):
46+
name_parts = CONFIG["accessConfig"].split('/')
47+
bucket_name = name_parts[2]
48+
bucket_object = "/".join(name_parts[3:])
49+
ACCESS = json.loads(aws_s3.Bucket(bucket_name).Object(bucket_object).get()["Body"].read().decode("utf-8"))
50+
else:
51+
with open(CONFIG["accessConfig"], "r") as file:
52+
ACCESS = json.load(file)
3753

3854
TOKEN_PROVIDER_URL = CONFIG["tokenProviderUrl"]
39-
print("Loaded config")
55+
print("Loaded configs")
4056

4157
token_public_key_encoded = requests.get(CONFIG["tokenPublicKeyUrl"], verify=False).json()["key"]
4258
TOKEN_PUBLIC_KEY = serialization.load_der_public_key(base64.b64decode(token_public_key_encoded))

src/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
urllib3
2+
cryptography
3+
jsonschema
4+
PyJWT
5+
requests
6+
boto3
7+
confluent_kafka

0 commit comments

Comments
 (0)