Here are some of the things that ChatGPT has taught me.
I asked ChatGPT (GPT-4) for a simple way to test VPC network connectivity without creating an EC2 instance in AWS.
It proposed creating the following lambda function that I could then configure in any of my VPCs and subnets. It works great!
import socket
import json
def lambda_handler(event, context):
domain = "domain_goes_here"
port = 1234 # port number goes here
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((domain, port))
sock.close()
return {
'statusCode': 200,
'body': json.dumps(f'Successfully connected to {domain}:{port}')
}
except Exception as e:
return {
'statusCode': 500,
'body': json.dumps(f'Failed to connect to {domain}:{port} - {str(e)}')
}