Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
fix: update provisioned concurrency to address cold starts (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssvegaraju committed Jul 21, 2022
1 parent 1f7ae17 commit f2969ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/cdk-infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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'),
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion lib/javaHapiValidator.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand All @@ -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}`);
}
}

0 comments on commit f2969ef

Please sign in to comment.