Every Glue Spark job is the same skeleton: parameters, contexts, Job, extract–transform–load, commit.
A Glue Spark job (job command glueetl) runs a Python script you store in S3. Glue starts the Spark cluster, then runs your script on the driver; the Spark work it triggers runs on the executors.
Almost every script opens with the same skeleton: read the job parameters, create a SparkContext, wrap it in a GlueContext, take the SparkSession from it, create a Job and call job.init(). The ETL goes in the middle and job.commit() closes it. Learn this shape once and every generated or hand-written Glue script becomes readable.
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)
# ... extract, transform, load ...
job.commit()Reach the last step for the run summary: the key takeaways from this lesson.