-
Notifications
You must be signed in to change notification settings - Fork 3
KMS-645: Enable API Gateway response caching and access logging for KMS read endpoints, with cache settings controlled via environment variables. #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
9bb8bce
KMS-645: Add caching to /concepts endpoubt
635dba2
KMS-645: Scoping to juse concepts.
2f7627a
KMS-645: Updated the cache key path
d09be3c
KMS-645: Send array
bbde70f
KMS-645: Removed cacheKeyParameters from stage.
0e43f8a
reduce response.
494a576
KMS-654: Increased ttl
975bcc7
KMS-645: Moved caching configuration to stage methodOptions
763e8c2
KMS-645: Removed integration request parameters, not needed.
38274f2
KMS-645: Added access logs.
bdbc45f
KMS-645: Moved to env vars. Now has custom access log.
6ccc21d
KMS-645: Added execution logs.
8a58118
KMS-645: Remove execution logs.
7cbb955
KMS-645: Lint issues
f5a1fdd
KMS-645: Fixed lint issues
53dd36a
KMS-645: Fixed lint issues
68a045f
KMS-645: More lint fixes
3710b4f
KMS-645: Removed unnecessary eslint override.
7a02c26
Merge branch 'KMS-645' of https://github.com/nasa/kms into KMS-645
58c219f
KMS-645: Added caching env variables.
1ab0b69
KMS-645: Added caching env vars.
fc57de7
KMS-645: Removed defaults
4aec377
KMS-647: Fix CDK lambda caching by keying lambdas on handlerPath + fu…
99de88c
Merge branch 'KMS-647' into KMS-645b
1389252
KMS-645b: Lets try without fullPath+
1114648
KMS-645: Temp removed fullPath endpoint
3d5442f
KMS-645b: Lets deliberately remove {fullPath+}
d04b918
KMS-645: Lets deliberately remove {fullPath+}
1e01a75
KMS-645b: Another try to remove {fullPath+}
bd986ec
KMS-645: Clear out any cdk context info from previous runs.
0d22f5c
KMS-645: Added cdk context clear
cf3ef32
KMS-645b: Adding npx cdk context --clear
2eaead4
KMS-645: Added back in fullPath+
503d3e2
KMS-645: Updated deploy bamboo
c0ebea3
KMS-645: Ensure AWS::ApiGateway::Deployment is created only after all…
5c1c412
KMS-647: Ensure AWS::ApiGateway::Deployment is created only after all…
80b3f86
Merge branch 'KMS-647' into KMS-645b
4577239
KMS-645b: Added custom resource for access log group.
644c727
KMS-647: Use an AwsCustomResource to create the CloudWatch Logs group…
ed03b67
KMS-647: This should not have access logs, that code belongs in KMS-645
ef133e6
KMS-647: Audit fix
821a185
KMS-645: Fix CDK deploy ordering and make access logs idempotent
5a5b19b
Merge branch 'KMS-647' into KMS-645
7a1a8f6
Merge branch 'main' into KMS-645
8030e79
KMS-645: Remove ;
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import * as cdk from 'aws-cdk-lib' | ||
| import * as apigateway from 'aws-cdk-lib/aws-apigateway' | ||
| import { Construct } from 'constructs' | ||
|
|
||
| /** | ||
| * Helper class to configure API Gateway caching for multiple endpoints | ||
| */ | ||
| export class ApiCacheSetup { | ||
| public static cacheMethodOptions( | ||
| cacheTtl: cdk.Duration | ||
| ): { [path: string]: apigateway.MethodDeploymentOptions } { | ||
| const cachePaths = [ | ||
| '/concepts/GET', | ||
| '/concepts/concept_scheme/{conceptScheme}/GET', | ||
| '/concepts/concept_scheme/{conceptScheme}/pattern/{pattern}/GET', | ||
| '/concepts/pattern/{pattern}/GET' | ||
| ] | ||
|
|
||
| return Object.fromEntries( | ||
| cachePaths.map((path) => [ | ||
| path, | ||
| { | ||
| cachingEnabled: true, | ||
| cacheTtl | ||
| } | ||
| ]) | ||
| ) as { [path: string]: apigateway.MethodDeploymentOptions } | ||
| } | ||
|
|
||
| /** | ||
| * Configures method request, integration request, and caching for specified endpoints | ||
| * @param scope - The construct scope | ||
| * @param api - The API Gateway REST API | ||
| * @param deployment - The API Gateway deployment | ||
| * @param stageName - The stage name | ||
| */ | ||
| public static configure( | ||
| _scope: Construct, | ||
| api: apigateway.IRestApi | ||
| ): void { | ||
| // Define query parameters for caching | ||
| const queryParams = { | ||
|
cgokey marked this conversation as resolved.
|
||
| 'method.request.querystring.page_num': false, | ||
| 'method.request.querystring.page_size': false, | ||
| 'method.request.querystring.format': false, | ||
| 'method.request.querystring.version': false | ||
| } | ||
|
|
||
| const cacheKeyParameters = [ | ||
| 'method.request.querystring.page_num', | ||
| 'method.request.querystring.page_size', | ||
| 'method.request.querystring.format', | ||
| 'method.request.querystring.version' | ||
| ] | ||
|
|
||
| // Helper to configure a single resource | ||
| const configureResource = ( | ||
| resourcePath: string[], | ||
| cacheNamespace: string | ||
| ) => { | ||
| const resource = resourcePath.reduce((acc, part) => { | ||
| const child = acc.getResource(part) | ||
|
|
||
| return child || acc | ||
| }, api.root) | ||
|
|
||
| if (!resourcePath.every((part) => resource.path.includes(part))) { | ||
| return | ||
| } | ||
|
|
||
| const getMethod = resource.node.findChild('GET') as apigateway.Method | ||
| if (getMethod) { | ||
| const cfnMethod = getMethod.node.defaultChild as apigateway.CfnMethod | ||
| cfnMethod.requestParameters = queryParams | ||
|
|
||
| const existingIntegration = cfnMethod.integration as | ||
| apigateway.CfnMethod.IntegrationProperty | ||
| if (existingIntegration) { | ||
| /* eslint-disable max-len */ | ||
| cfnMethod.integration = { | ||
| type: existingIntegration.type, | ||
| uri: existingIntegration.uri, | ||
| integrationHttpMethod: existingIntegration.integrationHttpMethod, | ||
| cacheNamespace, | ||
| cacheKeyParameters, | ||
| ...(existingIntegration.credentials && { | ||
| credentials: existingIntegration.credentials | ||
| }), | ||
| ...(existingIntegration.requestTemplates && { | ||
| requestTemplates: existingIntegration.requestTemplates | ||
| }), | ||
| ...(existingIntegration.integrationResponses && { | ||
| integrationResponses: existingIntegration.integrationResponses | ||
| }), | ||
| ...(existingIntegration.passthroughBehavior && { | ||
| passthroughBehavior: existingIntegration.passthroughBehavior | ||
| }), | ||
| ...(existingIntegration.connectionId && { | ||
| connectionId: existingIntegration.connectionId | ||
| }), | ||
| ...(existingIntegration.connectionType && { | ||
| connectionType: existingIntegration.connectionType | ||
| }), | ||
| ...(existingIntegration.contentHandling && { | ||
| contentHandling: existingIntegration.contentHandling | ||
| }), | ||
| ...(existingIntegration.timeoutInMillis && { | ||
| timeoutInMillis: existingIntegration.timeoutInMillis | ||
| }) | ||
| } | ||
| /* eslint-enable max-len */ | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Configure method and integration request for all endpoints | ||
| configureResource(['concepts'], 'concepts') | ||
| configureResource( | ||
| ['concepts', 'concept_scheme', '{conceptScheme}'], | ||
| 'concepts-scheme' | ||
| ) | ||
|
|
||
| configureResource([ | ||
| 'concepts', | ||
| 'concept_scheme', | ||
| '{conceptScheme}', | ||
| 'pattern', | ||
| '{pattern}' | ||
| ], 'concepts-scheme-pattern') | ||
|
|
||
| configureResource(['concepts', 'pattern', '{pattern}'], 'concepts-pattern') | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.