Skip to content

Commit d6946c2

Browse files
authored
Fix: [AEA-0000] - handle conversation for pull request - part 2 (#60)
## Summary - Routine Change ### Details - grant execute on pull request
1 parent 5627ebe commit d6946c2

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

packages/cdk/resources/Functions.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Construct} from "constructs"
22
import {LambdaFunction} from "../constructs/LambdaFunction"
3-
import {ManagedPolicy} from "aws-cdk-lib/aws-iam"
3+
import {ManagedPolicy, PolicyStatement, Role} from "aws-cdk-lib/aws-iam"
44
import {StringParameter} from "aws-cdk-lib/aws-ssm"
55
import {Secret} from "aws-cdk-lib/aws-secretsmanager"
66
import {TableV2} from "aws-cdk-lib/aws-dynamodb"
@@ -35,6 +35,8 @@ export interface FunctionsProps {
3535
readonly slackBotSigningSecret: Secret
3636
readonly slackBotStateTable: TableV2
3737
readonly promptName: string
38+
readonly isPullRequest: boolean
39+
readonly mainSlackBotLambdaExecutionRoleArn : string
3840
}
3941

4042
export class Functions extends Construct {
@@ -74,6 +76,30 @@ export class Functions extends Construct {
7476
props.slackBotTokenSecret.grantRead(slackBotLambda.function)
7577
props.slackBotSigningSecret.grantRead(slackBotLambda.function)
7678

79+
if (props.isPullRequest) {
80+
const mainSlackBotLambdaExecutionRole = Role.fromRoleArn(
81+
this,
82+
"mainRoleArn",
83+
props.mainSlackBotLambdaExecutionRoleArn, {
84+
mutable: true
85+
})
86+
87+
const executeSlackBotPolicy = new ManagedPolicy(this, "ExecuteSlackBotPolicy", {
88+
description: "foo",
89+
statements: [
90+
new PolicyStatement({
91+
actions: [
92+
"lambda:invokeFunction"
93+
],
94+
resources: [
95+
slackBotLambda.function.functionArn
96+
]
97+
})
98+
]
99+
})
100+
mainSlackBotLambdaExecutionRole.addManagedPolicy(executeSlackBotPolicy)
101+
}
102+
77103
// Lambda function to sync knowledge base on S3 events
78104
const syncKnowledgeBaseFunction = new LambdaFunction(this, "SyncKnowledgeBaseFunction", {
79105
stackName: props.stackName,

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
App,
33
Stack,
44
StackProps,
5-
CfnOutput
5+
CfnOutput,
6+
Fn
67
} from "aws-cdk-lib"
78
import {nagSuppressions} from "../nagSuppressions"
89
import {Apis} from "../resources/Apis"
@@ -30,6 +31,9 @@ export class EpsAssistMeStack extends Stack {
3031
public constructor(scope: App, id: string, props: EpsAssistMeStackProps) {
3132
super(scope, id, props)
3233

34+
// imports
35+
const mainSlackBotLambdaExecutionRoleArn = Fn.importValue("epsam:lambda:SlackBot:ExecutionRole:Arn")
36+
3337
// Get variables from context
3438
const region = Stack.of(this).region
3539
const account = Stack.of(this).account
@@ -131,7 +135,9 @@ export class EpsAssistMeStack extends Stack {
131135
slackBotTokenSecret: secrets.slackBotTokenSecret,
132136
slackBotSigningSecret: secrets.slackBotSigningSecret,
133137
slackBotStateTable: tables.slackBotStateTable.table,
134-
promptName: bedrockPromptResources.queryReformulationPrompt.promptName
138+
promptName: bedrockPromptResources.queryReformulationPrompt.promptName,
139+
isPullRequest: isPullRequest,
140+
mainSlackBotLambdaExecutionRoleArn: mainSlackBotLambdaExecutionRoleArn
135141
})
136142

137143
// Create vector index after Functions are created

0 commit comments

Comments
 (0)