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.
  • Loading branch information
rohanpm committed Mar 22, 2022
1 parent 9842120 commit 8d20157
Showing 1 changed file with 14 additions and 2 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

0 comments on commit 8d20157

Please sign in to comment.