Skip to content

Commit

Permalink
srm add failed event slack notification
Browse files Browse the repository at this point in the history
  • Loading branch information
raylrui committed Mar 3, 2025
1 parent 9477ba3 commit 47194bd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const vpcProps: VpcLookupOptions = {
},
};

// slack topic for event notification
export const slackTopicName = 'AwsChatBotTopic';

/**
* The SSM Parameter Name for HTTP Lambda Authorizer ARN defined in authorization stack manager
*/
Expand Down
4 changes: 2 additions & 2 deletions config/stacks/icaEventPipe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IcaEventPipeStackProps } from '../../lib/workload/stateful/stacks/ica-event-pipe/stack';
import { eventBusName, icaAwsAccountNumber } from '../constants';
import { eventBusName, icaAwsAccountNumber, slackTopicName } from '../constants';

export const getIcaEventPipeStackProps = (): IcaEventPipeStackProps => {
return {
name: 'IcaEventPipeStack',
eventBusName: eventBusName,
slackTopicName: 'AwsChatBotTopic',
slackTopicName: slackTopicName,
icaAwsAccountNumber: icaAwsAccountNumber,
};
};
6 changes: 6 additions & 0 deletions config/stacks/sequenceRunManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
region,
AppStage,
basespaceAccessTokenSecretName,
cognitoApiGatewayConfig,
Expand All @@ -7,10 +8,14 @@ import {
eventBusName,
logsApiGatewayConfig,
vpcProps,
slackTopicName,
accountIdAlias,
} from '../constants';
import { SequenceRunManagerStackProps } from '../../lib/workload/stateless/stacks/sequence-run-manager/deploy/stack';

export const getSequenceRunManagerStackProps = (stage: AppStage): SequenceRunManagerStackProps => {
const slackTopicArn =
'arn:aws:sns:' + region + ':' + accountIdAlias[stage] + ':' + slackTopicName;
return {
vpcProps,
lambdaSecurityGroupName: computeSecurityGroupName,
Expand All @@ -23,5 +28,6 @@ export const getSequenceRunManagerStackProps = (stage: AppStage): SequenceRunMan
customDomainNamePrefix: 'sequence',
},
bsshTokenSecretName: basespaceAccessTokenSecretName,
slackTopicArn: slackTopicArn,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { aws_lambda, aws_secretsmanager, Duration, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { ISecurityGroup, IVpc, SecurityGroup, Vpc, VpcLookupOptions } from 'aws-cdk-lib/aws-ec2';
import { EventBus, IEventBus, Rule } from 'aws-cdk-lib/aws-events';
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
import { Topic } from 'aws-cdk-lib/aws-sns';
import { LambdaFunction, SnsTopic } from 'aws-cdk-lib/aws-events-targets';
import { PythonFunction, PythonLayerVersion } from '@aws-cdk/aws-lambda-python-alpha';
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
import {
Expand All @@ -24,6 +25,7 @@ export interface SequenceRunManagerStackProps {
mainBusName: string;
apiGatewayCognitoProps: ApiGatewayConstructProps;
bsshTokenSecretName: string;
slackTopicArn: string;
}

export class SequenceRunManagerStack extends Stack {
Expand Down Expand Up @@ -92,9 +94,12 @@ export class SequenceRunManagerStack extends Stack {
compatibleArchitectures: [Architecture.ARM_64],
});

const topic: Topic = Topic.fromTopicArn(this, 'SlackTopic', props.slackTopicArn) as Topic;

this.createMigrationHandler();
this.createApiHandlerAndIntegration(props);
this.createProcSqsHandler();
this.createSlackNotificationHandler(topic);
}

private createPythonFunction(name: string, props: object): PythonFunction {
Expand Down Expand Up @@ -217,4 +222,28 @@ export class SequenceRunManagerStack extends Stack {

eventRule.addTarget(new LambdaFunction(fn));
}

private createSlackNotificationHandler(topic: Topic) {
/**
* subscribe to the 'SequenceRunStateChange' event, and send the slack notification toptic when the failed event is triggered.
*/

const eventRule = new Rule(this, this.stackName + 'EventRule', {
ruleName: this.stackName + 'EventRule',
description: 'Rule to send Failed SequenceRunStateChange events to the SlackTopic',
eventBus: this.mainBus,
});
eventRule.addEventPattern({
source: ['orcabus.sequencerunmanager'],
detailType: ['SequenceRunStateChange'],
detail: {
status: ['FAILED'],
id: [{ exists: true }],
instrumentRunId: [{ exists: true }],
sampleSheetName: [{ exists: true }],
startTime: [{ exists: true }],
},
});
eventRule.addTarget(new SnsTopic(topic));
}
}

0 comments on commit 47194bd

Please sign in to comment.