Skip to content

Commit

Permalink
refactor(platform): move cdk resource invoke, add stg and prod bucket…
Browse files Browse the repository at this point in the history
…s to config
  • Loading branch information
mmalenic committed Mar 21, 2024
1 parent 2270cca commit bca2417
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 63 deletions.
55 changes: 35 additions & 20 deletions config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { OrcaBusStatefulConfig } from '../lib/workload/orcabus-stateful-stack';
import { AuroraPostgresEngineVersion } from 'aws-cdk-lib/aws-rds';
import {
FilemanagerDependencies,
OrcaBusStatelessConfig,
} from '../lib/workload/orcabus-stateless-stack';
import { OrcaBusStatelessConfig } from '../lib/workload/orcabus-stateless-stack';
import { Duration, RemovalPolicy } from 'aws-cdk-lib';
import { EventSourceProps } from '../lib/workload/stateful/event_source/component';
import { DbAuthType } from '../lib/workload/stateless/postgres_manager/function/type';
import { FilemanagerConfig } from '../lib/workload/stateless/filemanager/deploy/lib/filemanager';

const regName = 'OrcaBusSchemaRegistry';
const eventBusName = 'OrcaBusMain';
const lambdaSecurityGroupName = 'OrcaBusLambdaSecurityGroup';
const dbClusterIdentifier = 'orcabus-db';
const dbClusterResourceIdParameterName = '/orcabus/db-cluster-resource-id';

const eventSourceQueueName = 'orcabus-event-source-queue';
const devBucket = 'umccr-temp-dev';
const stgBucket = 'umccr-temp-stg';
const prodBucket = 'org.umccr.data.oncoanalyser';

// Note, this should not end with a hyphen and 6 characters, otherwise secrets manager won't be
// able to find the secret using a partial ARN.
const rdsMasterSecretName = 'orcabus/master-rds'; // pragma: allowlist secret
Expand Down Expand Up @@ -87,20 +90,24 @@ const orcaBusStatelessConfig = {
},
};

const eventSourceConfig: EventSourceProps = {
queueName: 'orcabus-event-source-queue',
maxReceiveCount: 3,
rules: [
{
bucket: 'umccr-temp-dev',
},
],
const eventSourceConfig = (bucket: string): EventSourceProps => {
return {
queueName: eventSourceQueueName,
maxReceiveCount: 3,
rules: [
{
bucket,
},
],
};
};

const filemanagerDependencies: FilemanagerDependencies = {
eventSourceBuckets: ['umccr-temp-dev'],
eventSourceQueueName: eventSourceConfig.queueName,
databaseSecretName: orcaBusStatefulConfig.databaseProps.masterSecretName,
const filemanagerConfig = (bucket: string): FilemanagerConfig => {
return {
eventSourceQueueName: eventSourceQueueName,
databaseSecretName: orcaBusStatefulConfig.databaseProps.masterSecretName,
eventSourceBuckets: [bucket],
};
};

interface EnvironmentConfig {
Expand Down Expand Up @@ -152,11 +159,11 @@ export const getEnvironmentConfig = (
securityGroupProps: {
...orcaBusStatefulConfig.securityGroupProps,
},
eventSourceProps: eventSourceConfig,
eventSourceProps: eventSourceConfig(devBucket),
},
orcaBusStatelessConfig: {
...orcaBusStatelessConfig,
filemanagerDependencies: filemanagerDependencies,
filemanagerConfig: filemanagerConfig(devBucket),
},
},
};
Expand Down Expand Up @@ -186,8 +193,12 @@ export const getEnvironmentConfig = (
securityGroupProps: {
...orcaBusStatefulConfig.securityGroupProps,
},
eventSourceProps: eventSourceConfig(stgBucket),
},
orcaBusStatelessConfig: {
...orcaBusStatelessConfig,
filemanagerConfig: filemanagerConfig(stgBucket),
},
orcaBusStatelessConfig: orcaBusStatelessConfig,
},
};
break;
Expand All @@ -214,8 +225,12 @@ export const getEnvironmentConfig = (
securityGroupProps: {
...orcaBusStatefulConfig.securityGroupProps,
},
eventSourceProps: eventSourceConfig(prodBucket),
},
orcaBusStatelessConfig: {
...orcaBusStatelessConfig,
filemanagerConfig: filemanagerConfig(prodBucket),
},
orcaBusStatelessConfig: orcaBusStatelessConfig,
},
};
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type FunctionName = {
* Function name.
*/
functionName: string;
}
};

/**
* Props for the resource invoke construct.
Expand Down Expand Up @@ -101,7 +101,7 @@ export class CdkResourceInvoke<P, F extends InvokeFunction> extends Construct {
action: 'invoke',
parameters: {
FunctionName: this.function.functionName,
...(props.payload && { Payload: props.payload })
...(props.payload && { Payload: props.payload }),
},
physicalResourceId: PhysicalResourceId.of(
`${id}-AwsSdkCall-${this.function.currentVersion + this.hashValue(props.payload)}`
Expand Down
47 changes: 8 additions & 39 deletions lib/workload/orcabus-stateless-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Construct } from 'constructs';
import { getVpc } from './stateful/vpc/component';
import { MultiSchemaConstructProps } from './stateless/schema/component';
import { IVpc, ISecurityGroup, SecurityGroup } from 'aws-cdk-lib/aws-ec2';
import { Filemanager } from './stateless/filemanager/deploy/lib/filemanager';
import { Filemanager, FilemanagerConfig } from './stateless/filemanager/deploy/lib/filemanager';
import { Queue } from 'aws-cdk-lib/aws-sqs';
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
import {
Expand All @@ -20,22 +20,7 @@ export interface OrcaBusStatelessConfig {
lambdaSecurityGroupName: string;
rdsMasterSecretName: string;
postgresManagerConfig: PostgresManagerConfig;
filemanagerDependencies?: FilemanagerDependencies;
}

export interface FilemanagerDependencies {
/**
* Queue name used by the EventSource construct.
*/
eventSourceQueueName: string;
/**
* Buckets defined by the EventSource construct.
*/
eventSourceBuckets: string[];
/**
* Database secret name for the filemanager.
*/
databaseSecretName: string;
filemanagerConfig: FilemanagerConfig;
}

export class OrcaBusStatelessStack extends cdk.Stack {
Expand Down Expand Up @@ -70,15 +55,7 @@ export class OrcaBusStatelessStack extends cdk.Stack {

this.microserviceStackArray.push(this.createSequenceRunManager(props));
this.microserviceStackArray.push(this.createPostgresManager(props.postgresManagerConfig));

if (props.filemanagerDependencies) {
this.microserviceStackArray.push(
this.createFilemanager({
...props.filemanagerDependencies,
lambdaSecurityGroupName: props.lambdaSecurityGroupName,
})
);
}
this.microserviceStackArray.push(this.createFilemanager(props.filemanagerConfig));
}

private createSequenceRunManager(props: cdk.StackProps) {
Expand All @@ -98,38 +75,30 @@ export class OrcaBusStatelessStack extends cdk.Stack {
});
}

private createFilemanager(
dependencies: FilemanagerDependencies & { lambdaSecurityGroupName: string }
) {
private createFilemanager(config: FilemanagerConfig) {
// Opting to reconstruct the dependencies here, and pass them into the service as constructs.
const queue = Queue.fromQueueArn(
this,
'FilemanagerQueue',
Arn.format(
{
resource: dependencies.eventSourceQueueName,
resource: config.eventSourceQueueName,
service: 'sqs',
},
this
)
);
const databaseSecurityGroup = SecurityGroup.fromLookupByName(
this,
'FilemanagerDatabaseSecurityGroup',
dependencies.lambdaSecurityGroupName,
this.vpc
);
const databaseSecret = Secret.fromSecretNameV2(
this,
'FilemanagerDatabaseSecret',
dependencies.databaseSecretName
config.databaseSecretName
);

return new Filemanager(this, 'Filemanager', {
buckets: dependencies.eventSourceBuckets,
buckets: config.eventSourceBuckets,
buildEnvironment: {},
databaseSecret,
databaseSecurityGroup,
databaseSecurityGroup: this.lambdaSecurityGroup,
eventSources: [queue],
migrateDatabase: true,
vpc: this.vpc,
Expand Down
20 changes: 19 additions & 1 deletion lib/workload/stateless/filemanager/deploy/lib/filemanager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { Construct } from 'constructs';
import { IngestFunction, IngestFunctionProps } from '../constructs/functions/ingest';
import { CdkResourceInvoke } from '../../../functions/cdk_resource_invoke';
import { MigrateFunction } from '../constructs/functions/migrate';
import * as fn from '../constructs/functions/function';
import { IVpc } from 'aws-cdk-lib/aws-ec2';
import { IQueue } from 'aws-cdk-lib/aws-sqs';
import { DatabaseProps } from '../constructs/functions/function';
import { Stack, StackProps } from 'aws-cdk-lib';
import { CdkResourceInvoke } from '../../../../components/cdk_resource_invoke';

/**
* Stateful config for filemanager.
*/
export type FilemanagerConfig = {
/**
* Queue name used by the EventSource construct.
*/
eventSourceQueueName: string;
/**
* Buckets defined by the EventSource construct.
*/
eventSourceBuckets: string[];
/**
* Database secret name for the filemanager.
*/
databaseSecretName: string;
}

/**
* Props for the filemanager stack.
Expand Down
2 changes: 1 addition & 1 deletion test/stateless/cdkResourceInvoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as cdk from 'aws-cdk-lib';
import { Match, Template } from 'aws-cdk-lib/assertions';
import { CdkResourceInvoke } from '../../lib/workload/stateless/functions/cdk_resource_invoke';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { CdkResourceInvoke } from '../../lib/workload/components/cdk_resource_invoke';

let stack: cdk.Stack;
let vpc: ec2.Vpc;
Expand Down

0 comments on commit bca2417

Please sign in to comment.