eks tcp application pod에 대한 tcp 연결 테스트용 스크립트 작성
tcp_conn.py
import socket
def tcp_health_check(host, port):
message = "!!!HEALTH_CHECK!!!"
expected_responses = ["ok", "OK", "Ok"]
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((host, port))
print(f"Connected to {host} on port {port}")
sock.sendall(message.encode())
print(f"Sent: {message}")
response = sock.recv(1024).decode()
print(f"Received: {response}")
if response in expected_response:
print("Health check passed: received expected response.")
else:
print("Health check failed: unexpected response.")
except socket.error as e:
print(f"Socket error: {e}")
# Target port and IP or hostname
eks_pod_ip = "<pod ip or hostname>"
port = <target port>
# execute health check
tcp_health_check(eks_pod_ip, port)
'Development > Python' 카테고리의 다른 글
How to automatically stop Aurora MySQL RDS Clusters (0) | 2023.02.16 |
---|---|
automatically upload AWS WorkDocs files to specific AWS S3 in AWS cross account (0) | 2023.02.16 |
Simple function example of sending email as notification (0) | 2023.02.15 |