Amazon Amazon Elastic Compute Cloud (EC2)

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable computing capacity—literally, servers in Amazon's data centers—that you use to build and host your software systems.

Prerequisite Tasks

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

Operators

Start an Amazon EC2 instance

To start an Amazon EC2 instance you can use EC2StartInstanceOperator.

airflow/providers/amazon/aws/example_dags/example_ec2.py[source]

start_instance = EC2StartInstanceOperator(
    task_id="ec2_start_instance",
    instance_id=INSTANCE_ID,
)

Stop an Amazon EC2 instance

To stop an Amazon EC2 instance you can use EC2StopInstanceOperator.

airflow/providers/amazon/aws/example_dags/example_ec2.py[source]

stop_instance = EC2StopInstanceOperator(
    task_id="ec2_stop_instance",
    instance_id=INSTANCE_ID,
)

Sensors

Wait on an Amazon EC2 instance state

To check the state of an Amazon EC2 instance and wait until it reaches the target state you can use EC2InstanceStateSensor.

airflow/providers/amazon/aws/example_dags/example_ec2.py[source]

instance_state = EC2InstanceStateSensor(
    task_id="ec2_instance_state",
    instance_id=INSTANCE_ID,
    target_state="running",
)

Was this entry helpful?