Skip to content

Api authorizer performance - #947

Merged
greglucas merged 3 commits into
IMAP-Science-Operations-Center:devfrom
greglucas:api-authorizer-performance
Oct 18, 2025
Merged

Api authorizer performance#947
greglucas merged 3 commits into
IMAP-Science-Operations-Center:devfrom
greglucas:api-authorizer-performance

Conversation

@greglucas

Copy link
Copy Markdown
Collaborator

Change Summary

Overview

Improve performance of authorization of API Keys

closes #945

@greglucas greglucas added this to the October 2025 milestone Oct 17, 2025
@greglucas greglucas self-assigned this Oct 17, 2025

@laspsandoval laspsandoval left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caching will help a lot. Thanks Greg.

handler=self.api_key_authorizer_lambda,
response_types=[apigwv2_authorizers.HttpLambdaResponseType.SIMPLE],
identity_source=["$request.header.x-api-key"],
# Cache multiple requests with the same API key so we don't

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

handler="lambda_api_key_authorizer.lambda_handler",
code=lambda_.Code.from_asset("sds_data_manager/lambda_code/authorization"),
timeout=Duration.seconds(10),
memory_size=512, # Increase memory for larger network

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you come up with this number?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChatGPT told me this is a common number. I've used it other places too to get more throughput (1k seems excessive and probably wouldn't be worth the cost). We could go to 256 as well probably. Might be something we play with if needed.

@greglucas

Copy link
Copy Markdown
Collaborator Author

Agreed, the caching is the big win I think

This moves the table instantiation into the main body of the code
to cache it in the lambda execution environment.

Also inline the simple functions and remove the unnecessary logger.
Multiple requests with the same key will return the same result
rather than going through a lambda every time.
We don't care if the tests import things later which enables
mocks to be set up before any external imports
@greglucas
greglucas force-pushed the api-authorizer-performance branch from 7085448 to 73832c1 Compare October 18, 2025 01:40
@greglucas
greglucas merged commit 52ad711 into IMAP-Science-Operations-Center:dev Oct 18, 2025
2 checks passed
@greglucas
greglucas deleted the api-authorizer-performance branch October 18, 2025 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorization lambdas can be slow

2 participants