I've previously blogged how to view Glue Job execution history in a command line one-liner.
However, the date and time display was not good and it was difficult to use, so I rewrote it with a Python script.
import boto3
#If you want to use a profile other than default, specify it here
profile = "default"
session = boto3.session.Session(profile_name = profile)
client = session.client("glue")
jobs = client.get_jobs()
header = [
"started",
"completed",
"executionTime",
"status",
"name",
"allocatedCapacity",
"maxCapacity",
"glueVersion",
"errorMessage",
]
result = []
for job in jobs["Jobs"]:
name = job["Name"]
history = client.get_job_runs(JobName = name)
for run in history["JobRuns"]:
started = run["StartedOn"].strftime("%Y-%m-%d %H:%M:%S")
if "CompletedOn" in run:
completed = run["CompletedOn"].strftime("%Y-%m-%d %H:%M:%S")
else:
completed = ""
executionTime = str(run["ExecutionTime"])
if executionTime == "0":
executionTime = ""
status = run["JobRunState"]
if "ErrorMessage" in run:
errorMessage = run["ErrorMessage"]
else:
errorMessage = ""
allocatedCapacity = str(run["AllocatedCapacity"])
maxCapacity = str(run["MaxCapacity"])
glueVersion = str(run["GlueVersion"])
result.append([
started,
completed,
executionTime,
status,
name,
allocatedCapacity,
maxCapacity,
glueVersion,
errorMessage,
])
#Sort by startup time
result.sort(key = lambda r: r[0])
#Output tab-delimited
print("\t".join(header))
for r in result:
print("\t".join(r))
It displays the start time and end time, but it seems to be displayed in local time depending on the environment variable TZ
.
Recommended Posts