AWS EC2에서 curl을 이용한 RDS 접근 확인
2023. 1. 16. 17:02ㆍDev
728x90
반응형
AWS EC2에서 AWS RDS 접근 쉽게 확인하는 방법


일단 GPT에게 물어봅니다.
Q. how to connect test in ec2 to aws rds
A. To connect to an RDS instance from an EC2 instance, you will need to do the following:
- Make sure that the security group of the RDS instance allows connections from the security group of the EC2 instance.
- Get the endpoint and port number of the RDS instance.
- On the EC2 instance, use a tool such as the MySQL command line client or a programming language's database library to connect to the RDS instance using the endpoint and port number obtained in step 2.
- Provide the username and password for the RDS instance when prompted.
Please note that the above instructions are general and may vary depending on your specific use case and configurations.
- RDS 인스턴스의 보안 그룹이 EC2 인스턴스의 보안 그룹으로부터의 연결을 허용하는지 확인합니다.
- RDS 인스턴스의 엔드포인트와 포트 번호를 가져옵니다.
- EC2 인스턴스에서 MySQL 명령행 클라이언트나 프로그래밍 언어의 데이터베이스 라이브러리를 사용하여 엔드포인트와 포트번호를 통해 RDS 인스턴스에 연결합니다.
- RDS 인스턴스에서 요구하는 사용자 이름과 비밀번호를 입력합니다.
GPT가 알려주지 않는 방법으로 테스트 해보겠습니다.
1. RDS의 엔드포인트를 복사합니다. (DB식별자.난수.리전명.rds.amazonaws.com)
2. EC2에서 curl을 날립니다.
sh-4.2$ curl -v telnet://dbname-abcd.random.ap-northeast-2.rds.amazonaws.com:5432
* Trying 192.168.xxx.xxx:5432...
연결이 되지 않습니다.
3. 위 콘솔 화면에서 VPC 보안 그룹을 누릅니다.
4. DB 보안그룹 인바운드 규칙에 EC2 보안그룹을 추가합니다. (저는 PostgreSQL만 사용하려고 5432 포트만 열었습니다.)
5. 다시 EC2에서 curl을 날립니다.
sh-4.2$ curl -v telnet://dbname-abcd.random.ap-northeast-2.rds.amazonaws.com:5432
* Trying 192.168.xxx.xxx:5432...
* Connected to dbname-abcd.random.ap-northeast-2.rds.amazonaws.com (192.168.xxx.xxx) port 5432 (#0)
6. 연결을 확인할 수 있습니다.
https://aws.amazon.com/ko/premiumsupport/knowledge-center/rds-connectivity-instance-subnet-vpc/
VPC의 퍼블릭 또는 프라이빗 서브넷을 사용하여 Amazon RDS 인스턴스에 대한 연결 문제 해결
닫기 Arnab 씨의 동영상을 통해 자세히 알아보기(14:34)
aws.amazon.com
nslookup이나 네트워크 유틸리티, db명령어를 이용해서 할 수 도 있는데
이게 제일 편한것 같습니다.
알려주신 sc님께 감사드립니다...
'Dev' 카테고리의 다른 글
2023년 AWS 시험 프로모션 코드 (0) | 2023.02.20 |
---|---|
윈도우 wsl2 터미널 창 분할 단축키 (0) | 2023.02.10 |
쿠버네티스 스토리지 볼륨 정적 프로비저닝 vs 동적 프로비저닝 (1) | 2023.01.11 |
2022 회고와 2023 목표 (0) | 2022.12.29 |
쿠버네티스 오퍼레이터란? (1) | 2022.11.17 |