CDK design Encapsulation and Dependencies

0

This is a more of a design guideline question on CDK:

I have 2 separate Stacks for 2 different VPC. I need these VPCs to talk to each other. A lambda attached to VPC1 needs to call a resource in VPC2

In VPC1-Stack I have a peering connection to VPC2 In VPC2-Stack I have a SecurityGroup to allow incoming connection from the Lambda attached to VPC1

Its a headache when I have to make changes to either of the stacks. This is a kind of a circular dependency. At times I have had to destroy everything and redeploy.

VPC2 has my "Server / Service" and VPC1 has my "Client" so it seems counter-intuitive that the Server has dependency on the Client - or is that not the right way to think about this?

Am I condemned to suffer this circular dependency or the design Gods can offer some redemption with a better design?

  • Can you break the cycle by moving the Security Group to the same stack as the Lambda function?

  • Yes, I can do that. I can add ingress rule for lambda SG to the VPC2 SG. That would mean I change the SG of VPC2 from outside of VPC2 Stack - does that not break encapsulation or is it not the right way to think about this

질문됨 2년 전310회 조회
1개 답변
1

My understanding is the reference of VPC1's security group in VPC2 caused a dependency.

One way you can consider, to create encapsulation is to utilize VPC endpoint / AWS PrivateLink. You can expose the VPC2 services through PrivateLink and access the services in VPC1 and other VPCs through interface endpoint.

That way VPC1 and VPC2 would be completely independent and VPC2 has no reference of constructs in VPC1.

Jason_S
답변함 2년 전
  • Hi Jason_S

    Thanks for the answer

    Is it better design (and even possible) that in VPC1-stack I change VPC2's security group to allow connection from VPC1's Lambda? That way I break the circular dependency

    My VPC2 has an MSK cluster and my client is in VPC1.

    One way to think about this is: it makes sense that clients (VPC1 lambda) do the changes to the SG that they need to connect to the service. The service should not know about its clients but the clients should know about the service they need to consume - in terms of responsibility

    Another way to think about this is that if we allow clients to amend the SG of the MSK cluster, it probably breaks security? And what if VPC2-stack is rerun, would it remove the ingress rule? perhaps not

    Would love to hear your thoughts

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠