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

fix: update provisioned concurrency to address cold starts #661

Merged
merged 6 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);
}
}