From f2969ef1b67192773cd4df5c3d54cbdd0369d2dd Mon Sep 17 00:00:00 2001 From: Sukeerth Vegaraju Date: Thu, 21 Jul 2022 11:34:33 -0700 Subject: [PATCH] fix: update provisioned concurrency to address cold starts (#661) --- lib/cdk-infra-stack.ts | 13 ++++++------- lib/javaHapiValidator.ts | 5 ++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/cdk-infra-stack.ts b/lib/cdk-infra-stack.ts index 94a50901..5e7ccb86 100644 --- a/lib/cdk-infra-stack.ts +++ b/lib/cdk-infra-stack.ts @@ -537,6 +537,9 @@ export default class FhirWorksStack extends Stack { description: 'FHIR API Server', entry: path.join(__dirname, '../src/index.ts'), handler: 'handler', + currentVersionOptions: { + provisionedConcurrentExecutions: 5, + }, bundling: { ...defaultLambdaBundlingOptions, commandHooks: { @@ -558,17 +561,12 @@ export default class FhirWorksStack extends Stack { }, }, runtime: Runtime.NODEJS_14_X, - currentVersionOptions: { - provisionedConcurrentExecutions: 5, - }, environment: { ...lambdaDefaultEnvVars, EXPORT_STATE_MACHINE_ARN: bulkExportStateMachine.bulkExportStateMachine.stateMachineArn, PATIENT_COMPARTMENT_V3, PATIENT_COMPARTMENT_V4, - VALIDATOR_LAMBDA_ALIAS: props!.useHapiValidator - ? this.javaHapiValidator!.hapiValidatorLambda.functionArn - : '', + VALIDATOR_LAMBDA_ALIAS: props!.useHapiValidator ? this.javaHapiValidator!.alias.functionArn : '', }, role: new Role(this, 'fhirServerLambdaRole', { assumedBy: new ServicePrincipal('lambda.amazonaws.com'), @@ -666,10 +664,11 @@ export default class FhirWorksStack extends Stack { new PolicyStatement({ effect: Effect.ALLOW, actions: ['lambda:InvokeFunction'], - resources: [this.javaHapiValidator!.hapiValidatorLambda.functionArn], + resources: [this.javaHapiValidator!.alias.functionArn], }), ); } + fhirServerLambda.currentVersion.addAlias(`fhir-server-lambda-${props!.stage}`); const apiGatewayApiKey = apiGatewayRestApi.addApiKey('developerApiKey', { description: 'Key for developer access to the FHIR Api', diff --git a/lib/javaHapiValidator.ts b/lib/javaHapiValidator.ts index 7225ca47..93f8fdf4 100644 --- a/lib/javaHapiValidator.ts +++ b/lib/javaHapiValidator.ts @@ -1,5 +1,5 @@ import { Duration, Stack, StackProps } from 'aws-cdk-lib'; -import { Code, Function, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda'; +import { Alias, Code, Function, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda'; import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { Construct } from 'constructs'; import * as path from 'path'; @@ -13,6 +13,8 @@ export interface JavaHapiValidatorProps extends StackProps { export default class JavaHapiValidator extends Stack { hapiValidatorLambda: Function; + alias: Alias; + constructor(scope: Construct, id: string, props: JavaHapiValidatorProps) { super(scope, id, props); @@ -34,5 +36,6 @@ export default class JavaHapiValidator extends Stack { FHIR_VERSION: props.fhirVersion, }, }); + this.alias = this.hapiValidatorLambda.currentVersion.addAlias(`fhir-service-validator-lambda-${props.stage}`); } }