@@ -22,12 +22,12 @@ import {
2222} from "aws-cdk-lib/aws-bedrock"
2323import { RestApiGateway } from "../resources/RestApiGateway"
2424import { LambdaFunction } from "../resources/LambdaFunction"
25- import { nagSuppressions } from "../nagSuppressions"
2625import { LambdaIntegration } from "aws-cdk-lib/aws-apigateway"
2726import * as iam from "aws-cdk-lib/aws-iam"
2827import * as ops from "aws-cdk-lib/aws-opensearchserverless"
29- import * as ssm from "aws-cdk-lib/aws-ssm"
3028import * as cr from "aws-cdk-lib/custom-resources"
29+ import * as ssm from "aws-cdk-lib/aws-ssm"
30+ import { nagSuppressions } from "../nagSuppressions"
3131
3232export interface EpsAssistMeStackProps extends StackProps {
3333 readonly stackName : string
@@ -367,6 +367,15 @@ export class EpsAssistMeStack extends Stack {
367367 } )
368368 kbDataSource . node . addDependency ( kb )
369369
370+ // ==== IAM Policy for Lambda to read SSM parameters ====
371+ const slackLambdaSSMPolicy = new PolicyStatement ( {
372+ actions : [ "ssm:GetParameter" , "ssm:GetParameters" , "ssm:GetParameterHistory" ] ,
373+ resources : [
374+ slackBotTokenParameter . parameterArn ,
375+ slackSigningSecretParameter . parameterArn
376+ ]
377+ } )
378+
370379 // ==== Lambda environment variables ====
371380 const lambdaEnv : { [ key : string ] : string } = {
372381 RAG_MODEL_ID : "anthropic.claude-3-sonnet-20240229-v1:0" ,
@@ -396,15 +405,6 @@ export class EpsAssistMeStack extends Stack {
396405 additionalPolicies : [ ]
397406 } )
398407
399- // ==== IAM Policy for Lambda to read SSM parameters ====
400- const slackLambdaSSMPolicy = new PolicyStatement ( {
401- actions : [ "ssm:GetParameter" , "ssm:GetParameters" , "ssm:GetParameterHistory" ] ,
402- resources : [
403- slackBotTokenParameter . parameterArn ,
404- slackSigningSecretParameter . parameterArn
405- ]
406- } )
407-
408408 // ==== Lambda self-invoke policy (needed for Slack Bolt lazy handlers) ====
409409 const slackLambdaSelfInvokePolicy = new PolicyStatement ( {
410410 actions : [ "lambda:InvokeFunction" ] ,
@@ -446,18 +446,12 @@ export class EpsAssistMeStack extends Stack {
446446 trustStoreKey : "unused" ,
447447 truststoreVersion : "unused"
448448 } )
449-
450- // Grant the API Gateway role permission to invoke the Lambda function
451- apiGateway . role . addManagedPolicy ( slackBotLambda . executionPolicy )
452-
453- // Create API resources directly to avoid circular dependencies
454- const slackResource = apiGateway . api . root . addResource ( "slack" )
455- const askEpsResource = slackResource . addResource ( "ask-eps" )
456-
457- // Add the method with Lambda integration and explicit role
458- askEpsResource . addMethod ( "POST" , new LambdaIntegration ( slackBotLambda . function , {
449+ // Add SlackBot Lambda to API Gateway
450+ const slackRoute = apiGateway . api . root . addResource ( "slack" ) . addResource ( "ask-eps" )
451+ slackRoute . addMethod ( "POST" , new LambdaIntegration ( slackBotLambda . function , {
459452 credentialsRole : apiGateway . role
460453 } ) )
454+ apiGateway . role . addManagedPolicy ( slackBotLambda . executionPolicy )
461455
462456 // ==== Output: SlackBot Endpoint ====
463457 new CfnOutput ( this , "SlackBotEndpoint" , {
0 commit comments