Skip to content

Commit 81ace32

Browse files
committed
PERF: Add a ttl cache to the API Gateway authorizer
Multiple requests with the same key will return the same result rather than going through a lambda every time.
1 parent c02b687 commit 81ace32

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

sds_data_manager/constructs/api_gateway_construct.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
handler="lambda_api_key_authorizer.lambda_handler",
106106
code=lambda_.Code.from_asset("sds_data_manager/lambda_code/authorization"),
107107
timeout=Duration.seconds(10),
108+
memory_size=512, # Increase memory for larger network
108109
)
109110

110111
# Create or reference the API Keys DynamoDB table
@@ -124,6 +125,9 @@ def __init__(
124125
handler=self.api_key_authorizer_lambda,
125126
response_types=[apigwv2_authorizers.HttpLambdaResponseType.SIMPLE],
126127
identity_source=["$request.header.x-api-key"],
128+
# Cache multiple requests with the same API key so we don't
129+
# invoke the lambda repeatedly for the same key
130+
results_cache_ttl=Duration.hours(12),
127131
)
128132

129133
# Add a custom domain to the API if we have one

0 commit comments

Comments
 (0)