airflow.providers.amazon.aws.hooks.ec2

Module Contents

Classes

EC2Hook

Interact with Amazon Elastic Compute Cloud (EC2).

Functions

only_client_type(func)

airflow.providers.amazon.aws.hooks.ec2.only_client_type(func)[source]
class airflow.providers.amazon.aws.hooks.ec2.EC2Hook(api_type='resource_type', *args, **kwargs)[source]

Bases: airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook

Interact with Amazon Elastic Compute Cloud (EC2).

Provide thick wrapper around boto3.client("ec2") or boto3.resource("ec2").

Parameters

api_type – If set to client_type then hook use boto3.client("ec2") capabilities, If set to resource_type then hook use boto3.resource("ec2") capabilities.

Additional arguments (such as aws_conn_id) may be specified and are passed down to the underlying AwsBaseHook.

API_TYPES[source]
get_instance(instance_id, filters=None)[source]

Get EC2 instance by id and return it.

Parameters
  • instance_id (str) – id of the AWS EC2 instance

  • filters (list | None) – List of filters to specify instances to get

Returns

Instance object

stop_instances(instance_ids)[source]

Stop instances with given ids.

Parameters

instance_ids (list) – List of instance ids to stop

Returns

Dict with key StoppingInstances and value as list of instances being stopped

Return type

dict

start_instances(instance_ids)[source]

Start instances with given ids.

Parameters

instance_ids (list) – List of instance ids to start

Returns

Dict with key StartingInstances and value as list of instances being started

Return type

dict

terminate_instances(instance_ids)[source]

Terminate instances with given ids.

Parameters

instance_ids (list) – List of instance ids to terminate

Returns

Dict with key TerminatingInstances and value as list of instances being terminated

Return type

dict

describe_instances(filters=None, instance_ids=None)[source]

Describe EC2 instances, optionally applying filters and selective instance ids.

Parameters
  • filters (list | None) – List of filters to specify instances to describe

  • instance_ids (list | None) – List of instance IDs to describe

Returns

Response from EC2 describe_instances API

get_instances(filters=None, instance_ids=None)[source]

Get list of instance details, optionally applying filters and selective instance ids.

Parameters
  • instance_ids (list | None) – List of ids to get instances for

  • filters (list | None) – List of filters to specify instances to get

Returns

List of instances

Return type

list

get_instance_ids(filters=None)[source]

Get list of instance ids, optionally applying filters to fetch selective instances.

Parameters

filters (list | None) – List of filters to specify instances to get

Returns

List of instance ids

Return type

list

async get_instance_state_async(instance_id)[source]
get_instance_state(instance_id)[source]

Get EC2 instance state by id and return it.

Parameters

instance_id (str) – id of the AWS EC2 instance

Returns

current state of the instance

Return type

str

wait_for_state(instance_id, target_state, check_interval)[source]

Wait EC2 instance until its state is equal to the target_state.

Parameters
  • instance_id (str) – id of the AWS EC2 instance

  • target_state (str) – target state of instance

  • check_interval (float) – time in seconds that the job should wait in between each instance state checks until operation is completed

Returns

None

Return type

None

Was this entry helpful?