How I Review AI-Generated Python Code
How to save time with AI while improving code quality.
5 min read Just now
No matter what, you'll always be writing custom monitoring code for cloud services despite the number of monitoring features AWS provides. Recently, I had the pleasure of writing a service in response to an unforeseen outage. I loaded up PyCharm (VIM users, please spare me) and navigated to my good friend ChatGPT to hash this out.
Part of this monitoring job required a call to retrieve a list of ECS services based on the cluster name, and I prefixed the names of the services for filtering.
With this information, I started with a simple prompt for ChatGPT to get the ball rolling.
Write code to match a prefix to a list of services on an ECS cluster
It gave a lovely function that worked out of the box.
import boto3
from botocore.exceptions import BotoCoreError, ClientError
def match_services_with_prefix(cluster_name, prefix):
ecs_client = boto3.client("ecs")
matched_services = []
next_token = None
try:
while True:
response = ecs_client.list_services(
cluster=cluster_name,
nextToken=next_token
)
service_arns = response.get("serviceArns", [])
# Extract service…