Skip to content

Commit 175460e

Browse files
committed
add policy
1 parent 54f3cd5 commit 175460e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/cdk/resources/Functions.ts

Lines changed: 25 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"
@@ -75,6 +75,30 @@ export class Functions extends Construct {
7575
props.slackBotTokenSecret.grantRead(slackBotLambda.function)
7676
props.slackBotSigningSecret.grantRead(slackBotLambda.function)
7777

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

0 commit comments

Comments
 (0)