ECS - EC2 Instance Type, Bridge Network mode can't connect private subnet

0

I'm trying to run Spring Application with EC2 Instance Type in ECS service. This EC2 Instance Type is located on the Public Subnet.

This Spring Application connects to the RDS located on the Private Subnet, and logs that fail each time are checked. Security groups are open on both sides and both are inside the same VPC.

If you change the network mode to awsvpc, the connection between Spring and RDS is made, but the port of the container and the EC2 Host port are not mapped, which is a problem.

There are two questions I would like to ask for help, and if I can get an answer from either of them, I would like to use it to solve the problem.

  1. Why is Public Subnet's Spring Application unable to connect to Private Subnet's RDS in Bridge Network Mode and solutions

  2. How to map host ports and container ports in awsvpc mode

Thanks for your help!

1개 답변
0

Recommend that you move your EC2 to the Private Subnet and you either use an Application Load Balancer or API Gateway to provide external access to your application. The subnets are meant to be configured so that Private has access to Public but not the other way around. Here's more information on this - https://www.learnaws.org/2022/06/22/public-private-subnets/#:~:text=a%20public%20subnet.-,When%20to%20use%20Public%20%26%20Private%20Subnets%3F,created%20in%20a%20public%20subnet.

Here's the document on how to setup the application as I described: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-example-private-subnets-nat.html

Hope this helps.

profile picture
답변함 일 년 전
profile picture
전문가
검토됨 24일 전

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

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

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

관련 콘텐츠