Home / AWS

AWSRunbookAdvanced

AWS Glue ETL job failed or timed out: read the real error, fix out-of-memory executors, VPC connection timeouts and job bookmarks

A Glue Spark job is FAILED, TIMEOUT or quietly processed nothing. Find the real exception, then fix memory, VPC connection, concurrency and job bookmark problems and rerun safely.

Deepak Bhardwaj7 min read

Applies toAWS Glue 3.0, 4.0 and 5.0 Spark jobs, AWS CLI v2

The morning load is late, and the Glue job shows FAILED, TIMEOUT or ERROR. Or it shows SUCCEEDED after processing zero rows. This runbook finds the real exception, maps it to the usual causes and reruns the job without loading data twice.

Triage: what does the run say?

JOB=orders-daily-etl

aws glue get-job-runs --job-name "$JOB" --max-items 5 \
  --query 'JobRuns[].{id:Id,state:JobRunState,start:StartedOn,secs:ExecutionTime,workers:NumberOfWorkers,type:WorkerType,err:ErrorMessage}' \
  --output table
JobRunState Meaning Go to
FAILED Script or Spark exception Read the error log (step 1)
TIMEOUT Run passed the job's Timeout (minutes) Skew, too few workers or a hung connection
ERROR Glue couldn't start or run the job (role, network, quota) Check ErrorMessage, IAM and the connection
STOPPED Someone or something stopped it CloudTrail BatchStopJobRun
SUCCEEDED with no output Bookmark skipped the data, or the source was empty Job bookmarks section

Then pull the full run detail and the job definition:

aws glue get-job-run --job-name "$JOB" --run-id jr_0123abcd... \
  --query 'JobRun.{state:JobRunState,err:ErrorMessage,args:Arguments,version:GlueVersion,dpuSecs:DPUSeconds}'

aws glue get-job --job-name "$JOB" \
  --query 'Job.{version:GlueVersion,worker:WorkerType,n:NumberOfWorkers,timeout:Timeout,maxConc:ExecutionProperty.MaxConcurrentRuns,conns:Connections.Connections,args:DefaultArguments}'

Step 1: read the real exception

ErrorMessage is often truncated or generic (An error occurred while calling o123.pyWriteDynamicFrame). The driver log has the full stack trace.

On Glue 5.0, continuous logging is on by default: driver, executor and Glue logger output goes to /aws-glue/jobs/error, and script stdout to /aws-glue/jobs/output. On 4.0 and earlier you need --enable-continuous-cloudwatch-log true for live logs, which go to /aws-glue/jobs/logs-v2. Log group names vary by version and by --custom-logGroup-prefix, so check the job's arguments if you can't find them.

The log stream name starts with the run ID:

RUN=jr_0123abcd...
aws logs filter-log-events --log-group-name /aws-glue/jobs/error \
  --log-stream-name-prefix "$RUN" \
  --filter-pattern '?Exception ?Error ?"Traceback"' \
  --query 'events[].message' --output text | head -80

Tip

Add --enable-job-insights true to the job's default arguments. Failed runs then get an extra log stream with exception analysis that points to the line in your script that failed and suggests a fix.

Symptom → cause → fix

Error text (partial) Cause Fix
Container killed by YARN for exceeding memory limits, java.lang.OutOfMemoryError, executor lost Skewed partition, huge collect()/toPandas(), too-large files per task Larger worker type, repartition, avoid driver-side collects
Connection timed out / Could not connect to JDBC source Glue ENIs can't reach the database Security group, subnet routes, DB allow list
At least one security group must open all ingress ports Connection security group lacks a self-referencing rule Add an all-TCP inbound rule from the same security group
Endpoint or Unable to execute HTTP request to S3 or Glue VPC subnet has no S3 or NAT path S3 gateway endpoint, Glue/STS interface endpoints or NAT
ConcurrentRunsExceededException MaxConcurrentRuns reached Fix the overlapping schedule or raise the value
AccessDeniedException / S3 403 Job role missing S3, KMS or Lake Formation permission Fix the role, key policy or LF grants
Job bookmark update failed due to version mismatch Two runs updated the same bookmark Don't run the same bookmarked job concurrently

Fix: out-of-memory executors and drivers

First decide whether the driver or the executors ran out. The stack trace tells you: executor loss shows in executor logs and ExecutorLostFailure; driver OOM kills the whole run quickly.

Driver OOM usually comes from the script: collect(), toPandas(), count() on a huge frame in a loop, or listing millions of small S3 files. Remove driver-side collects and, for many small files, use grouping on S3 reads:

dyf = glueContext.create_dynamic_frame.from_options(
    connection_type="s3",
    connection_options={
        "paths": ["s3://raw-bucket/orders/"],
        "recurse": True,
        "groupFiles": "inPartition",
        "groupSize": "134217728",   # ~128 MB per group
    },
    format="json",
)

Executor OOM usually comes from skew or too-large tasks. Check the Spark UI (enable --enable-spark-ui true with --spark-event-logs-path s3://...) for one task that runs much longer than the rest. Then:

  • Repartition on a better-distributed key before wide joins or aggregations.
  • Move up a worker type (G.1X to G.2X, or the larger and memory-optimised types where your Glue version and Region offer them). Check the current worker types for your version.
  • Turn on auto scaling (--enable-auto-scaling true, Glue 3.0 and later) so NumberOfWorkers becomes a ceiling.

Warning

aws glue update-job replaces the whole job definition. Fields you leave out of --job-update, such as connections, default arguments or the timeout, are reset. Export the job first and edit the full definition.

aws glue get-job --job-name "$JOB" --query 'Job' > job.json
# edit job.json: remove Name, CreatedOn, LastModifiedOn; change WorkerType / NumberOfWorkers
aws glue update-job --job-name "$JOB" --job-update file://job.json

Depending on the job, get-job can return both MaxCapacity and WorkerType. Keep only one of them in the update, or the call is rejected.

Fix: VPC connection timeouts

A job with a Glue connection runs ENIs in the connection's subnet using its security group. Check all of these:

aws glue get-connection --name orders-postgres \
  --query 'Connection.{type:ConnectionType,url:ConnectionProperties.JDBC_CONNECTION_URL,subnet:PhysicalConnectionRequirements.SubnetId,sgs:PhysicalConnectionRequirements.SecurityGroupIdList,az:PhysicalConnectionRequirements.AvailabilityZone}'

aws ec2 describe-security-groups --group-ids sg-0glue1234 \
  --query 'SecurityGroups[].IpPermissions'
  • Self-referencing inbound rule: all TCP from the same security group, so the Spark nodes can talk to each other.
  • Outbound: to the database port and to 443.
  • Database side: its security group or firewall allows the Glue security group or subnet CIDR.
  • Routes: S3 gateway endpoint on the subnet's route table, plus a NAT gateway or interface endpoints for Glue, STS, CloudWatch Logs and KMS if the job uses them.
  • Free IPs: each worker takes an IP in the subnet. A nearly full subnet causes ERROR at start.

Use Test connection on the connection in the Glue console to check reachability from that subnet without running the job.

Fix: job bookmarks that skip or reprocess data

Bookmarks track what a job already processed per source, keyed by transformation_ctx. Common problems:

  • Job succeeded with zero rows: the bookmark is ahead of the data, often after files were re-uploaded with older timestamps.
  • Data loaded twice: job.commit() was never reached, or transformation_ctx was renamed, so Glue treated the source as new.
  • Nothing tracked at all: the source read has no transformation_ctx, or job.init() / job.commit() is missing.
aws glue get-job-bookmark --job-name "$JOB" --query 'JobBookmarkEntry.{run:RunId,attempt:Attempt,version:Version,state:JobBookmark}'

Choose the rerun mode deliberately:

# Reprocess everything from scratch (target must be idempotent or cleaned first)
aws glue reset-job-bookmark --job-name "$JOB"

# Rerun without moving the bookmark, e.g. to backfill
aws glue start-job-run --job-name "$JOB" \
  --arguments '{"--job-bookmark-option":"job-bookmark-pause"}'

Caution

Resetting a bookmark on a job that appends to its target duplicates every row it has ever loaded. Before you reset, truncate or overwrite the target partitions, or make the write idempotent with a merge, overwrite or dynamic partition overwrite.

Rerun and confirm

aws glue start-job-run --job-name "$JOB" --query JobRunId --output text
aws glue get-job-run --job-name "$JOB" --run-id <new-run-id> --query 'JobRun.JobRunState'

Check the row counts in the target against the source for the affected partition before you tell downstream teams it's fixed.

Prevent it next time

  • Create an EventBridge rule on Glue Job State Change with state in FAILED, TIMEOUT or ERROR, and send it to SNS or your incident tool.
  • Set a realistic Timeout per job instead of the default, so a hung run fails in an hour rather than running for most of a day.
  • Keep MaxConcurrentRuns at 1 for bookmarked jobs and space out schedules and triggers so runs can't overlap.
  • Make writes idempotent so that a retry, reset or backfill is always safe.
  • Turn on job run insights and continuous logging on every production job.
  • Give Glue its own subnets sized for your peak worker count, with S3 and other required endpoints tested.