Skip to content

Commit

Permalink
fix cdk construct
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 committed Oct 28, 2024
1 parent aa4acaf commit 230ba54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions bin/stacks/routing-lambda-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class RoutingLambdaStack extends cdk.NestedStack {
layers: [
aws_lambda.LayerVersion.fromLayerVersionArn(
this,
'InsightsLayer',
'CachingInsightsLayer',
`arn:aws:lambda:${region}:580247275435:layer:LambdaInsightsExtension:14`
),
],
Expand All @@ -248,7 +248,7 @@ export class RoutingLambdaStack extends cdk.NestedStack {
threshold: 0.05,
evaluationPeriods: 3,
})
const lambdaAlarmErrorRate = new aws_cloudwatch.Alarm(this, 'RoutingAPI-LambdaErrorRate', {
const lambdaAlarmErrorRate = new aws_cloudwatch.Alarm(this, 'CachingRoutingAPI-LambdaErrorRate', {
metric: new aws_cloudwatch.MathExpression({
expression: 'errors / invocations',
usingMetrics: {
Expand All @@ -266,7 +266,7 @@ export class RoutingLambdaStack extends cdk.NestedStack {
evaluationPeriods: 3,
})

const cachingLambdaThrottlesErrorRate = new aws_cloudwatch.Alarm(this, 'RoutingAPI-LambdaThrottles', {
const cachingLambdaThrottlesErrorRate = new aws_cloudwatch.Alarm(this, 'CachingRoutingAPI-LambdaThrottles', {
metric: cachingRoutingLambda.metricThrottles({
period: Duration.minutes(5),
statistic: 'sum',
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
let routeCachingProvider: IRouteCachingProvider | undefined = undefined

if (Math.random() * 100 < (newCachedRoutesRolloutPercent ?? 0)) {
if (CACHED_ROUTES_TABLE_NAME && CACHED_ROUTES_TABLE_NAME !== '' && CACHING_ROUTING_LAMBDA_FUNCTION_NAME) {
if (CACHED_ROUTES_TABLE_NAME && CACHED_ROUTES_TABLE_NAME !== '') {
routeCachingProvider = new DynamoRouteCachingProvider({
routesTableName: ROUTES_TABLE_NAME!,
routesCachingRequestFlagTableName: ROUTES_CACHING_REQUEST_FLAG_TABLE_NAME!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ interface ConstructorParams {
/**
* The Lambda Function Name for the Lambda that will be invoked to fill the cache
*/
cachingQuoteLambdaName: string
cachingQuoteLambdaName?: string
}

export class DynamoRouteCachingProvider extends IRouteCachingProvider {
private readonly ddbClient: DynamoDB.DocumentClient
private readonly lambdaClient: Lambda
private readonly routesTableName: string
private readonly routesCachingRequestFlagTableName: string
private readonly cachingQuoteLambdaName: string
private readonly cachingQuoteLambdaName?: string

private readonly DEFAULT_CACHEMODE_ROUTES_DB = CacheMode.Livemode
private readonly ROUTES_DB_TTL = 24 * 60 * 60 // 24 hours
Expand Down Expand Up @@ -312,15 +312,17 @@ export class DynamoRouteCachingProvider extends IRouteCachingProvider {
},
}

const params = {
FunctionName: this.cachingQuoteLambdaName,
InvocationType: 'Event',
Payload: JSON.stringify(payload),
}
if (this.cachingQuoteLambdaName) {
const params = {
FunctionName: this.cachingQuoteLambdaName,
InvocationType: 'Event',
Payload: JSON.stringify(payload),
}

log.info(`[DynamoRouteCachingProvider] Sending async caching request to lambda ${JSON.stringify(params)}`)
log.info(`[DynamoRouteCachingProvider] Sending async caching request to lambda ${JSON.stringify(params)}`)

this.lambdaClient.invoke(params).promise()
this.lambdaClient.invoke(params).promise()
}
}

private setRoutesDbCachingIntentFlag(
Expand Down

0 comments on commit 230ba54

Please sign in to comment.