22
33import com .unicorn .constructs .EksCluster ;
44import software .amazon .awscdk .*;
5- import software .amazon .awscdk .services .ec2 .IVpc ;
6- import software .amazon .awscdk .services .ec2 .SecurityGroup ;
7- import software .amazon .awscdk .services .ec2 .SubnetSelection ;
8- import software .amazon .awscdk .services .ec2 .SubnetType ;
5+ import software .amazon .awscdk .services .ec2 .*;
96import software .amazon .awscdk .services .iam .*;
107import software .amazon .awscdk .services .lambda .Code ;
118import software .amazon .awscdk .services .lambda .Function ;
@@ -31,10 +28,33 @@ public InfrastructureLambdaBedrock(Construct scope, String id, String region, Bu
3128 // Create a security group for the Lambda function
3229 SecurityGroup lambdaSg = SecurityGroup .Builder .create (this , "LambdaSecurityGroup" )
3330 .vpc (vpc )
31+ .securityGroupName ("unicornstore-thread-dump-lambda-sg" )
3432 .description ("Security group for Thread Dump Lambda function" )
3533 .allowAllOutbound (true )
3634 .build ();
3735
36+ // Allow Lambda to communicate with EKS API server
37+ // The Kubernetes API typically runs on port 443 (HTTPS)
38+ eksCluster .getClusterSecurityGroup ().addIngressRule (
39+ Peer .securityGroupId (lambdaSg .getSecurityGroupId ()),
40+ Port .tcp (443 ),
41+ "Allow Lambda access to Kubernetes API"
42+ );
43+
44+ // Allow Lambda to reach EKS cluster
45+ lambdaSg .addEgressRule (
46+ Peer .securityGroupId (eksCluster .getClusterSecurityGroup ().getSecurityGroupId ()),
47+ Port .tcp (443 ),
48+ "Allow Lambda to reach Kubernetes API"
49+ );
50+
51+ // Allow EKS cluster to respond back to Lambda
52+ eksCluster .getClusterSecurityGroup ().addIngressRule (
53+ Peer .securityGroupId (lambdaSg .getSecurityGroupId ()),
54+ Port .tcp (443 ),
55+ "Allow Lambda access to Kubernetes API"
56+ );
57+
3858 // IAM Role for Bedrock
3959 Role bedrockRole = Role .Builder .create (this , "BedrockAccessRole" )
4060 .assumedBy (new ServicePrincipal ("bedrock.amazonaws.com" ))
0 commit comments