From 8b98da9eaae0e52d64c9150bd0ffc3b71025c2cc Mon Sep 17 00:00:00 2001 From: Tim Nguyen Date: Thu, 3 Jun 2021 15:54:42 -0400 Subject: [PATCH] fix: Allow running sls offline with Hapi Validator (#343) --- DEVELOPMENT.md | 13 ++++++++++++- serverless.yaml | 5 +++++ src/config.ts | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 4854d983..f3208dd7 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -32,7 +32,18 @@ Once the script has finished running, you can run `yarn watch` in the directory `AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= OFFLINE_BINARY_BUCKET= OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT= serverless offline start` -If you don't know the `OFFLINE_BINARY_BUCKET` and `OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT` value, you can run `serverless info --verbose` in the deployment package directory. +### Local Development with Implementation Guides + +If you're using [Implementation Guides](./USING_IMPLEMENTATION_GUIDES.md), then follow these steps to run FHIR Works with IG locally. You'll need to provide the `OFFLINE_LAMBDA_VALIDATOR_ALIAS`. + +Run this command in the `deployment` package directory to start your local environment: + +`AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= OFFLINE_BINARY_BUCKET= OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT= OFFLINE_VALIDATOR_LAMBDA_ALIAS= serverless offline start` + +The command above runs the local FHIR server with the appropriate environment variables. + +If you don't know the value for `OFFLINE_BINARY_BUCKET`,`OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT`, and `OFFLINE_VALIDATOR_LAMBDA_ALIAS` value, run the following command in the deployment package directory: `serverless info --verbose` + ## Deploy Local Packages to AWS diff --git a/serverless.yaml b/serverless.yaml index c88212b5..76b1def0 100644 --- a/serverless.yaml +++ b/serverless.yaml @@ -688,6 +688,11 @@ resources: ] Export: Name: !Join ['-', [CloudwatchExecutionLogGroup, !Ref Stage, Arn]] + ValidatorLambdaAlias: + Condition: isUsingHapiValidator + Description: Arn of Hapi Validator lambda + Value: + Fn::ImportValue: "fhir-service-validator-lambda-${self:custom.stage}" plugins: - serverless-step-functions diff --git a/src/config.ts b/src/config.ts index 6b89310e..205944f9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -35,9 +35,12 @@ const dynamoDbBundleService = new DynamoDbBundleService(DynamoDb); // Configure the input validators. Validators run in the order that they appear on the array. Use an empty array to disable input validation. const validators: Validator[] = []; -if (process.env.VALIDATOR_LAMBDA_ALIAS) { +if (process.env.VALIDATOR_LAMBDA_ALIAS && process.env.VALIDATOR_LAMBDA_ALIAS !== '[object Object]') { // The HAPI FHIR Validator must be deployed separately. It is the recommended choice when using implementation guides. validators.push(new HapiFhirLambdaValidator(process.env.VALIDATOR_LAMBDA_ALIAS)); +} else if (process.env.OFFLINE_VALIDATOR_LAMBDA_ALIAS) { + // Allows user to run sls offline with custom provided HAPI Lambda + validators.push(new HapiFhirLambdaValidator(process.env.OFFLINE_VALIDATOR_LAMBDA_ALIAS)); } else { // The JSON Schema Validator is simpler and is a good choice for testing the FHIR server with minimal configuration. validators.push(new JsonSchemaValidator(fhirVersion));