Skip to content

Commit

Permalink
Allow AWS endpoint URL to be customized
Browse files Browse the repository at this point in the history
If EXODUS_AWS_ENDPOINT_URL env var is set, we'll use that as the AWS
endpoint URL when constructing boto clients.

This will never be used in production. The motivation is only to enable
testing against an instance of localstack.

The same applies to the reftest support script, as that also works fine
against localstack if the endpoint URL is set. Though reftest has
command-line arguments, the same env var is used there for consistency.
  • Loading branch information
rohanpm committed Mar 22, 2022
1 parent 9842120 commit 639bee1
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 639bee1

Please sign in to comment.