AWS Glue

AWS Glue is a serverless data integration service that makes it easy to discover, prepare, and combine data for analytics, machine learning, and application development. AWS Glue provides all the capabilities needed for data integration so that you can start analyzing your data and putting it to use in minutes instead of months.

Prerequisite Tasks

To use these operators, you must do a few things:

Operators

Create an AWS Glue crawler

AWS Glue Crawlers allow you to easily extract data from various data sources. To create a new AWS Glue Crawler or run an existing one you can use GlueCrawlerOperator.

tests/system/providers/amazon/aws/example_glue.py[source]

crawl_s3 = GlueCrawlerOperator(
    task_id="crawl_s3",
    config=glue_crawler_config,
)

Note

The AWS IAM role included in the config needs access to the source data location (e.g. s3:PutObject access if data is stored in Amazon S3) as well as the AWSGlueServiceRole policy. See the References section below for a link to more details.

Submit an AWS Glue job

To submit a new AWS Glue job you can use GlueJobOperator.

tests/system/providers/amazon/aws/example_glue.py[source]

submit_glue_job = GlueJobOperator(
    task_id="submit_glue_job",
    job_name=glue_job_name,
    script_location=f"s3://{bucket_name}/etl_script.py",
    s3_bucket=bucket_name,
    iam_role_name=role_name,
    create_job_kwargs={"GlueVersion": "3.0", "NumberOfWorkers": 2, "WorkerType": "G.1X"},
)

Note

The same AWS IAM role used for the crawler can be used here as well, but it will need policies to provide access to the output location for result data.

Sensors

Wait on an AWS Glue crawler state

To wait on the state of an AWS Glue crawler execution until it reaches a terminal state you can use GlueCrawlerSensor.

tests/system/providers/amazon/aws/example_glue.py[source]

wait_for_crawl = GlueCrawlerSensor(
    task_id="wait_for_crawl",
    crawler_name=glue_crawler_name,
)

Wait on an AWS Glue job state

To wait on the state of an AWS Glue Job until it reaches a terminal state you can use GlueJobSensor

tests/system/providers/amazon/aws/example_glue.py[source]

wait_for_job = GlueJobSensor(
    task_id="wait_for_job",
    job_name=glue_job_name,
    # Job ID extracted from previous Glue Job Operator task
    run_id=submit_glue_job.output,
    verbose=True,  # prints glue job logs in airflow logs
)

Was this entry helpful?