Skip to content

Commit

Permalink
Merge pull request #330 from rohanpm/endpoint-url
Browse files Browse the repository at this point in the history
Allow AWS endpoint URL to be customized
  • Loading branch information
rohanpm committed Mar 22, 2022
2 parents 7aff280 + 639bee1 commit 3bedcdf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 14 additions & 2 deletions exodus_lambda/functions/origin_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

CONF_FILE = os.environ.get("EXODUS_LAMBDA_CONF_FILE") or "lambda_config.json"

# Endpoint for AWS services.
# Normally, should be None.
# You might want to try e.g. "https://localhost:3377" if you want to test
# this code against localstack.
ENDPOINT_URL = os.environ.get("EXODUS_AWS_ENDPOINT_URL") or None


class OriginRequest(LambdaBase):
def __init__(self, conf_file=CONF_FILE):
Expand All @@ -29,15 +35,21 @@ def __init__(self, conf_file=CONF_FILE):
@property
def db_client(self):
if not self._db_client:
self._db_client = boto3.client("dynamodb", region_name=self.region)
self._db_client = boto3.client(
"dynamodb",
region_name=self.region,
endpoint_url=ENDPOINT_URL,
)

return self._db_client

@property
def sm_client(self):
if not self._sm_client:
self._sm_client = boto3.client(
"secretsmanager", region_name=self.region
"secretsmanager",
region_name=self.region,
endpoint_url=ENDPOINT_URL,
)

return self._sm_client
Expand Down
6 changes: 4 additions & 2 deletions support/reftest/reftest
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ from tqdm import tqdm

DATA_DIR = os.path.dirname(__file__)

ENDPOINT_URL = os.environ.get("EXODUS_AWS_ENDPOINT_URL") or None


class DBHandler:
def __init__(self, table, config_table, session):
self.dynamodb = session.client("dynamodb")
self.dynamodb = session.client("dynamodb", endpoint_url=ENDPOINT_URL)
self.table = table
self.config_table = config_table

Expand Down Expand Up @@ -93,7 +95,7 @@ class DBHandler:

class S3Handler:
def __init__(self, bucket, session):
self.s3_client = session.client("s3")
self.s3_client = session.client("s3", endpoint_url=ENDPOINT_URL)
self.bucket = bucket

def upload_from_localfile(self, path, checksum):
Expand Down

0 comments on commit 3bedcdf

Please sign in to comment.