Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1734 adding config and maintenance window #56

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
7 changes: 5 additions & 2 deletions infra/config/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export const config: EnvConfig = {
},
domain: "metriport.com",
subdomain: "fhir",
dbName: "my_db",
dbUsername: "my_db_user",
fhirDatabase: {
name: "my_db",
username: "my_db_user",
maintenanceWindow: "Sun:02:00-Sun:02:30",
},
};
export default config;
34 changes: 30 additions & 4 deletions infra/lib/env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,40 @@ export type EnvConfig = {
environmentType: EnvType;
region: string;
vpcId: string;
zone: { // Private hosted zone for this region
zone: {
// Private hosted zone for this region
id: string;
name: string;
}
};
domain: string;
subdomain: string;
dbName: string;
dbUsername: string;
fhirDatabase: {
/**
* The name of the database.
*/
name: string;
/**
* The FHIR username to connect to the database.
*/
username: string;
/**
* From CDK: A preferred maintenance window day/time range. Should be specified as a range ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC).
*
* Example: 'Sun:23:45-Mon:00:15'.
*
* Must be at least 30 minutes long.
*
* @see: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_UpgradeDBInstance.Maintenance.html#Concepts.DBMaintenance
*/
maintenanceWindow: string;
/**
* From CDK: The minimum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster.
*
* You can specify ACU values in half-step increments, such as 8, 8.5, 9, and so on. The smallest value that you can use is 0.5.
*
* @see — http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-dbcluster-serverlessv2scalingconfiguration.html#cfn-rds-dbcluster-serverlessv2scalingconfiguration-mincapacity
*/
};
slack?: {
workspaceId: string;
alertsChannelId: string;
Expand Down
14 changes: 7 additions & 7 deletions infra/lib/fhir-server-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ export class FHIRServerStack extends Stack {
const { minDBCap, maxDBCap, minSlowLogDurationInMs } = settings();

// create database credentials
const dbConfig = props.config.fhirDatabase;
const dbClusterName = "fhir-server";
const dbName = props.config.dbName;
const dbUsername = props.config.dbUsername;
const dbPasswordSecret = new secret.Secret(this, "FHIRServerDBPassword", {
secretName: "FHIRServerDBPassword",
generateSecretString: {
Expand All @@ -125,7 +124,7 @@ export class FHIRServerStack extends Stack {
},
});
const dbCreds = Credentials.fromPassword(
dbUsername,
dbConfig.username,
dbPasswordSecret.secretValue
);
// aurora serverlessv2 db
Expand All @@ -148,8 +147,9 @@ export class FHIRServerStack extends Stack {
vpc: this.vpc,
instanceType: new InstanceType("serverless"),
},
preferredMaintenanceWindow: dbConfig.maintenanceWindow,
credentials: dbCreds,
defaultDatabaseName: dbName,
defaultDatabaseName: dbConfig.name,
clusterIdentifier: dbClusterName,
storageEncrypted: true,
parameterGroup,
Expand All @@ -174,7 +174,7 @@ export class FHIRServerStack extends Stack {

return {
dbCluster,
dbCreds: { username: dbUsername, password: dbPasswordSecret },
dbCreds: { username: dbConfig.username, password: dbPasswordSecret },
};
}

Expand Down Expand Up @@ -205,10 +205,10 @@ export class FHIRServerStack extends Stack {

// Prep DB related data to the server
if (!dbCreds.password) throw new Error(`Missing DB password`);
const dbConfig = props.config.fhirDatabase;
const dbAddress = dbCluster.clusterEndpoint.hostname;
const dbPort = dbCluster.clusterEndpoint.port;
const dbName = props.config.dbName;
const dbUrl = `jdbc:postgresql://${dbAddress}:${dbPort}/${dbName}`;
const dbUrl = `jdbc:postgresql://${dbAddress}:${dbPort}/${dbConfig.name}`;

// Run some servers on fargate containers
const fargateService =
Expand Down
7 changes: 6 additions & 1 deletion infra/lib/shared/cloudwatch-metric.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Alarm, ComparisonOperator, Metric, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
import {
Alarm,
ComparisonOperator,
Metric,
TreatMissingData,
} from "aws-cdk-lib/aws-cloudwatch";
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
import { Construct } from "constructs";

Expand Down
6 changes: 4 additions & 2 deletions infra/lib/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export async function initConfig(node: Node): Promise<EnvConfig> {
const configPath = `../../config/${env}.ts`;
const configModule = await import(configPath);
if (!configModule || !configModule.default) {
throw new Error(`Ensure config is defined, could not fine file ${configPath}`);
throw new Error(
`Ensure config is defined, could not fine file ${configPath}`
);
}
config = configModule.default as EnvConfig;
return config;
}
}
10 changes: 8 additions & 2 deletions infra/lib/shared/target-group.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Duration } from "aws-cdk-lib";
import { ComparisonOperator, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
import {
ComparisonOperator,
TreatMissingData,
} from "aws-cdk-lib/aws-cloudwatch";
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
import { ApplicationTargetGroup, HttpCodeTarget } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import {
ApplicationTargetGroup,
HttpCodeTarget,
} from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { Construct } from "constructs";
import { addAlarmToMetric } from "../shared/cloudwatch-metric";

Expand Down
Loading