-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-4171]: Add cache updater api stack
- Loading branch information
Showing
5 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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
55 changes: 55 additions & 0 deletions
55
cdk-infra/lib/constructs/cache-updater/cache-updater-api-construct.ts
This file contains 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,55 @@ | ||
import { Duration } from 'aws-cdk-lib'; | ||
import { Cors, LambdaIntegration, LambdaRestApi } from 'aws-cdk-lib/aws-apigateway'; | ||
import { TaskDefinition } from 'aws-cdk-lib/aws-ecs'; | ||
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; | ||
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; | ||
import { Construct } from 'constructs'; | ||
import path from 'path'; | ||
|
||
interface CacheUpdaterApiConstructProps { | ||
clusterName: string; | ||
taskDefinition: TaskDefinition; | ||
containerName: string; | ||
} | ||
|
||
const HANDLERS_PATH = path.join(__dirname, '/../../../../api/controllers/v2'); | ||
|
||
export class CacheUpdaterApiConstruct extends Construct { | ||
constructor( | ||
scope: Construct, | ||
id: string, | ||
{ clusterName, taskDefinition, containerName }: CacheUpdaterApiConstructProps | ||
) { | ||
super(scope, id); | ||
|
||
const cacheWebhookLambda = new NodejsFunction(this, 'cacheUpdaterWebhookLambda', { | ||
entry: `${HANDLERS_PATH}/cache.ts`, | ||
handler: 'rebuildCacheHandler', | ||
runtime: Runtime.NODEJS_18_X, | ||
timeout: Duration.minutes(2), | ||
memorySize: 1024, | ||
environment: { | ||
CLUSTER: clusterName, | ||
TASK_DEFINITION: taskDefinition.taskDefinitionArn, | ||
CONTAINER_NAME: containerName, | ||
}, | ||
}); | ||
|
||
taskDefinition.grantRun(cacheWebhookLambda); | ||
|
||
// generic handler for the root endpoint | ||
const rootEndpointLambda = new Function(this, 'RootEndpointLambda', { | ||
code: Code.fromInline('exports.default = (event) => { console.log("hello, world!!"); }'), | ||
runtime: Runtime.NODEJS_18_X, | ||
handler: 'RootEndpointLambda', | ||
}); | ||
|
||
const restApi = new LambdaRestApi(this, 'cacheUpdaterRestApi', { handler: rootEndpointLambda, proxy: false }); | ||
|
||
restApi.root | ||
.addResource('webhook', { | ||
defaultCorsPreflightOptions: { allowOrigins: Cors.ALL_ORIGINS }, | ||
}) | ||
.addMethod('POST', new LambdaIntegration(cacheWebhookLambda)); | ||
} | ||
} |
This file contains 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 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