Skip to content

Commit

Permalink
replace with a resource policy to fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
raylrui committed Mar 4, 2025
1 parent d648ade commit 34661c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 1 addition & 5 deletions config/stacks/sequenceRunManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
region,
AppStage,
basespaceAccessTokenSecretName,
cognitoApiGatewayConfig,
Expand All @@ -9,13 +8,10 @@ import {
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 @@ -28,6 +24,6 @@ export const getSequenceRunManagerStackProps = (stage: AppStage): SequenceRunMan
customDomainNamePrefix: 'sequence',
},
bsshTokenSecretName: basespaceAccessTokenSecretName,
slackTopicArn: slackTopicArn,
slackTopicName: slackTopicName,
};
};
21 changes: 15 additions & 6 deletions lib/workload/stateless/stacks/sequence-run-manager/deploy/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
HttpRoute,
HttpRouteKey,
} from 'aws-cdk-lib/aws-apigatewayv2';
import { ManagedPolicy, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { ManagedPolicy, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { ApiGatewayConstruct, ApiGatewayConstructProps } from '../../../../components/api-gateway';
import { Architecture } from 'aws-cdk-lib/aws-lambda';
import { PostgresManagerStack } from '../../../../stateful/stacks/postgres-manager/deploy/stack';
Expand All @@ -25,7 +25,7 @@ export interface SequenceRunManagerStackProps {
mainBusName: string;
apiGatewayCognitoProps: ApiGatewayConstructProps;
bsshTokenSecretName: string;
slackTopicArn: string;
slackTopicName: string;
}

export class SequenceRunManagerStack extends Stack {
Expand Down Expand Up @@ -94,12 +94,10 @@ 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);
this.createSlackNotificationHandler(props.slackTopicName);
}

private createPythonFunction(name: string, props: object): PythonFunction {
Expand Down Expand Up @@ -223,10 +221,21 @@ export class SequenceRunManagerStack extends Stack {
eventRule.addTarget(new LambdaFunction(fn));
}

private createSlackNotificationHandler(topic: Topic) {
private createSlackNotificationHandler(topicName: string) {
/**
* subscribe to the 'SequenceRunStateChange' event, and send the slack notification toptic when the failed event is triggered.
*/
const slackTopicArn = 'arn:aws:sns:' + this.region + ':' + this.account + ':' + topicName;
const topic: Topic = Topic.fromTopicArn(this, 'SlackTopic', slackTopicArn) as Topic;

// Add a resource policy to allow EventBridge to publish to this SNS topic.
topic.addToResourcePolicy(
new PolicyStatement({
principals: [new ServicePrincipal('events.amazonaws.com')],
actions: ['sns:Publish'],
resources: [topic.topicArn],
})
);

const eventRule = new Rule(this, this.stackName + 'EventSlackNotificationRule', {
ruleName: this.stackName + 'EventSlackNotificationRule',
Expand Down

0 comments on commit 34661c9

Please sign in to comment.