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=test_setup['glue_crawler_config'],
    # Waits by default, set False to test the Sensor below
    wait_for_completion=False,
)

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=test_setup['glue_job_name'],
    script_location=f's3://{test_setup["bucket_name"]}/etl_script.py',
    s3_bucket=test_setup['bucket_name'],
    iam_role_name=test_setup['role_name'],
    create_job_kwargs={'GlueVersion': '3.0', 'NumberOfWorkers': 2, 'WorkerType': 'G.1X'},
    # Waits by default, set False to test the Sensor below
    wait_for_completion=False,
)

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=test_setup['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=test_setup['glue_job_name'],
    # Job ID extracted from previous Glue Job Operator task
    run_id=submit_glue_job.output,
)

Was this entry helpful?