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

Commit 51d9e2c

Browse files
authored
feat!: Move deployment pipeline to CDK (#654)
1 parent 532c169 commit 51d9e2c

39 files changed

+6156
-2891
lines changed

.eslintignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
auditLogMover/
1+
auditLogMover/
2+
cdk.out/

.github/workflows/deploy.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ jobs:
106106
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
107107
run: |
108108
serverless deploy --stage dev --region ${{ matrix.region }} --useHapiValidator true --enableMultiTenancy ${{ matrix.enableMultiTenancy }} --enableSubscriptions true --conceal
109+
- name: Deploy FHIR Server and Hapi Validator with CDK
110+
env:
111+
AWS_ACCESS_KEY_ID: ${{ secrets.CDK_AWS_ACCESS_KEY_ID }}
112+
AWS_SECRET_ACCESS_KEY: ${{ secrets.CDK_AWS_SECRET_ACCESS_KEY }}
113+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
114+
run: |
115+
yarn deploy -c region=${{ matrix.region }} -c useHapiValidator=true -c enableMultiTenancy=${{ matrix.enableMultiTenancy }} -c enableSubscriptions=true --all
109116
- name: Deploy auditLogMover
110117
env:
111118
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID}}
@@ -159,6 +166,20 @@ jobs:
159166
--auth-flow USER_PASSWORD_AUTH --auth-parameters USERNAME=$COGNITO_USERNAME,PASSWORD=$COGNITO_PASSWORD | \
160167
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["AuthenticationResult"]["IdToken"]')
161168
bundle exec rake crucible:execute_hearth_tests[$SERVICE_URL,$API_KEY,$ACCESS_TOKEN]
169+
- name: Execute tests on CDK
170+
env:
171+
SERVICE_URL: ${{ secrets.CDK_SERVICE_URL }}
172+
API_KEY: ${{ secrets.CDK_API_KEY }}
173+
COGNITO_CLIENT_ID: ${{ secrets.CDK_COGNITO_CLIENT_ID }}
174+
COGNITO_USERNAME: ${{ secrets.CDK_COGNITO_USERNAME_PRACTITIONER }}
175+
COGNITO_PASSWORD: ${{ secrets.CDK_COGNITO_PASSWORD }}
176+
AWS_ACCESS_KEY_ID: ${{ secrets.CDK_AWS_ACCESS_KEY_ID}}
177+
AWS_SECRET_ACCESS_KEY: ${{ secrets.CDK_AWS_SECRET_ACCESS_KEY }}
178+
run: |
179+
ACCESS_TOKEN=$(aws cognito-idp initiate-auth --region us-west-2 --client-id $COGNITO_CLIENT_ID \
180+
--auth-flow USER_PASSWORD_AUTH --auth-parameters USERNAME=$COGNITO_USERNAME,PASSWORD=$COGNITO_PASSWORD | \
181+
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["AuthenticationResult"]["IdToken"]')
182+
bundle exec rake crucible:execute_hearth_tests[$SERVICE_URL,$API_KEY,$ACCESS_TOKEN]
162183
custom-integration-tests:
163184
needs: crucible-test
164185
name: Run custom integration tests - enableMultiTenancy=${{ matrix.enableMultiTenancy }}
@@ -174,6 +195,12 @@ jobs:
174195
subscriptionsNotificationsTableSecretName: SUBSCRIPTIONS_NOTIFICATIONS_TABLE
175196
subscriptionsEndpointSecretName: SUBSCRIPTIONS_ENDPOINT
176197
subscriptionsApiKeySecretName: SUBSCRIPTIONS_API_KEY
198+
cdk_serviceUrlSecretName: CDK_SERVICE_URL
199+
cdk_cognitoClientIdSecretName: CDK_COGNITO_CLIENT_ID
200+
cdk_apiKeySecretName: CDK_API_KEY
201+
cdk_subscriptionsNotificationsTableSecretName: CDK_SUBSCRIPTIONS_NOTIFICATIONS_TABLE
202+
cdk_subscriptionsEndpointSecretName: CDK_SUBSCRIPTIONS_ENDPOINT
203+
cdk_subscriptionsApiKeySecretName: CDK_SUBSCRIPTIONS_API_KEY
177204
- enableMultiTenancy: true
178205
region: us-west-1
179206
serviceUrlSecretName: MULTITENANCY_SERVICE_URL
@@ -182,6 +209,12 @@ jobs:
182209
subscriptionsNotificationsTableSecretName: MULTITENANCY_SUBSCRIPTIONS_NOTIFICATIONS_TABLE
183210
subscriptionsEndpointSecretName: MULTITENANCY_SUBSCRIPTIONS_ENDPOINT
184211
subscriptionsApiKeySecretName: MULTITENANCY_SUBSCRIPTIONS_API_KEY
212+
cdk_serviceUrlSecretName: CDK_MT_SERVICE_URL
213+
cdk_cognitoClientIdSecretName: CDK_MT_COGNITO_CLIENT_ID
214+
cdk_apiKeySecretName: CDK_MT_API_KEY
215+
cdk_subscriptionsNotificationsTableSecretName: CDK_SUBSCRIPTIONS_NOTIFICATIONS_TABLE
216+
cdk_subscriptionsEndpointSecretName: CDK_SUBSCRIPTIONS_ENDPOINT
217+
cdk_subscriptionsApiKeySecretName: CDK_SUBSCRIPTIONS_API_KEY
185218
steps:
186219
- name: Checkout
187220
uses: actions/checkout@v2
@@ -211,6 +244,25 @@ jobs:
211244
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
212245
AWS_REGION: ${{ matrix.region }}
213246
run: yarn int-test
247+
- name: Execute tests on CDK
248+
env:
249+
API_URL: ${{ secrets[matrix.cdk_serviceUrlSecretName] }}
250+
API_KEY: ${{ secrets[matrix.cdk_apiKeySecretName] }}
251+
API_AWS_REGION: ${{ matrix.region }}
252+
COGNITO_CLIENT_ID: ${{ secrets[matrix.cdk_cognitoClientIdSecretName] }}
253+
COGNITO_USERNAME_PRACTITIONER: ${{ secrets.CDK_COGNITO_USERNAME_PRACTITIONER }}
254+
COGNITO_USERNAME_AUDITOR: ${{ secrets.CDK_COGNITO_USERNAME_AUDITOR }}
255+
COGNITO_USERNAME_PRACTITIONER_ANOTHER_TENANT: ${{ secrets.CDK_COGNITO_USERNAME_PRACTITIONER_ANOTHER_TENANT }}
256+
COGNITO_PASSWORD: ${{ secrets.CDK_COGNITO_PASSWORD }}
257+
MULTI_TENANCY_ENABLED: ${{ matrix.enableMultiTenancy }}
258+
SUBSCRIPTIONS_ENABLED: 'true'
259+
SUBSCRIPTIONS_NOTIFICATIONS_TABLE: ${{ secrets[matrix.cdk_subscriptionsNotificationsTableSecretName] }}
260+
SUBSCRIPTIONS_ENDPOINT: ${{ secrets[matrix.cdk_subscriptionsEndpointSecretName] }}
261+
SUBSCRIPTIONS_API_KEY: ${{ secrets[matrix.cdk_subscriptionsApiKeySecretName] }}
262+
AWS_ACCESS_KEY_ID: ${{ secrets.CDK_AWS_ACCESS_KEY_ID}}
263+
AWS_SECRET_ACCESS_KEY: ${{ secrets.CDK_AWS_SECRET_ACCESS_KEY }}
264+
AWS_REGION: ${{ matrix.region }}
265+
run: yarn int-test
214266

215267
merge-develop-to-mainline:
216268
needs: custom-integration-tests

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
#*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
build
10+
dist
11+
12+
/implementationGuides
13+
/compiledImplementationGuides/*
14+
!/compiledImplementationGuides/gitkeep
15+
116
/.serverless
217
/.vscode
318
!/.gitignore

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

CONTRIBUTING.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ Code for FHIR Works on AWS is written in TypeScript. This requires your IDE to b
1616
1717
### AWS Cloud deployment
1818

19-
In order to re-build and re-deploy services to AWS after changes were made, you can run serverless commands (like [severless deploy](https://www.serverless.com/framework/docs/providers/aws/cli-reference/deploy/)) directly from this deployment package or rerun the `install.sh` or `win-install.ps1` script. If you need more help please check in [AWS service deployment](./INSTALL.md#aws-service-deployment).
19+
In order to re-build and re-deploy services to AWS after changes were made, you can run CDK commands (like [cdk deploy](https://docs.aws.amazon.com/cdk/v2/guide/cli.html) directly from this deployment package. If you need more help please check in [AWS service deployment](./INSTALL.md#aws-service-deployment).
2020

2121
### Local deployment
2222

23-
It can be quicker to deploy the FHIR API locally to test instead of running a complete Cloud based deployment. This deployment is temporary and will not be listening to further connection attempts once the local service is stopped. Deploy locally using
23+
It can be quicker to deploy the FHIR API locally to test instead of running a complete Cloud based deployment. This deployment is temporary and will not be listening to further connection attempts once the local service is stopped. You can follow [this guide](https://docs.aws.amazon.com/cdk/v2/guide/cli.html) to deploy locally with the AWS SAM CLI. You may need to define the appropriate environment variables if they are not already defined:
24+
* ACCESS_KEY (This is your AWS Access Key)
25+
* SECRET_KEY (This is your AWS Secret Key)
26+
* OFFLINE_BINARY_BUCKET
27+
* OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT
28+
Some of these values can all be found in the output of the deploy command, or in the `INFO_OUTPUT.log` file:
29+
* FHIR_SERVER_BINARY_BUCKET
30+
* ELASTIC_SEARCH_DOMAIN_ENDPOINT
2431

25-
```sh
26-
ACCESS_KEY=<AWS_ACCESS_KEY> SECRET_KEY=<AWS_SECRET_KEY> OFFLINE_BINARY_BUCKET=<FHIR_SERVER_BINARY_BUCKET> OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT=<ELASTIC_SEARCH_DOMAIN_ENDPOINT> sls offline start
27-
```
2832

29-
Once you start the server locally, take note of the API Key that is generated. When making a request to the local server, you will need that key for the header _x-api-key_. The key is defined in the output as `Key with token: <API_KEY>`
33+
Once you start the server locally, take note of the API Key that is generated. When making a request to the local server, you will need that key for the header _x-api-key_. The key can be found under the API Gateway service in the AWS Console.
3034

3135
## Reporting Bugs/Feature Requests
3236

CUSTOMIZE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ The FHIR Works on AWS deployment can be customized to provide CORS support for b
5757
generateServerlessRouter(fhirConfig, genericResources, corsOptions)
5858
```
5959
Please see the available [configuration options](https://www.npmjs.com/package/cors#configuration-options).
60-
- For pre-flight request support, add an OPTIONS method to the API Gateway `{proxy+}` route within the Serverless template. The request should be handled by the Lambda handler. The method should not use authorization.
61-
- If using a custom authorizer, then rejected requests also need to provide CORS headers, otherwise it is tricky to interpret the unauthorized response in the browser. The following [blog](https://www.serverless.com/blog/cors-api-gateway-survival-guide) describes how a `GatewayResponse` resource may be added to the Serverless template to provide these headers.
60+
- For pre-flight request support, add an OPTIONS method to the API Gateway `{proxy+}` route within the CloudFormation template. The request should be handled by the Lambda handler. The method should not use authorization.
61+
- If using a custom authorizer, then rejected requests also need to provide CORS headers, otherwise it is tricky to interpret the unauthorized response in the browser. The following [blog](https://www.serverless.com/blog/cors-api-gateway-survival-guide) describes how a `GatewayResponse` resource may be added to the Serverless template to provide these headers. This can be adapted to the CDK template by following the [GatewayResponse](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.GatewayResponse.html) construct documentation.
6262

6363
## Supporting other FHIR implementation guides or profiles
6464

0 commit comments

Comments
 (0)