Skip to content

Instantly share code, notes, and snippets.

@dnorton
Last active March 27, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnorton/008e65d46eff89415ff73ddd4badc350 to your computer and use it in GitHub Desktop.
Save dnorton/008e65d46eff89415ff73ddd4badc350 to your computer and use it in GitHub Desktop.
Things ChatGPT Taught Me

Here are some of the things that ChatGPT has taught me.

Use a Lambda to check network connectivity

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)}')
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment