airflow.providers.amazon.aws.hooks.ec2

Module Contents

Classes

EC2Hook

Interact with AWS EC2 Service.

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 AWS EC2 Service.

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

See also

AwsBaseHook

API_TYPES[source]
get_instance(self, instance_id: str, filters: list = None)[source]

Get EC2 instance by id and return it.

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

  • filters (list) -- List of filters to specify instances to get

Returns

Instance object

Return type

ec2.Instance

stop_instances(self, instance_ids: list) dict[source]

Stop instances with given ids

Parameters

instance_ids -- List of instance ids to stop

Returns

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

start_instances(self, instance_ids: list) dict[source]

Start instances with given ids

Parameters

instance_ids -- List of instance ids to start

Returns

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

terminate_instances(self, instance_ids: list) dict[source]

Terminate instances with given ids

Parameters

instance_ids -- List of instance ids to terminate

Returns

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

describe_instances(self, filters: list = None, instance_ids: list = None)[source]

Describe EC2 instances, optionally applying filters and selective instance ids

Parameters
  • filters -- List of filters to specify instances to describe

  • instance_ids -- List of instance IDs to describe

Returns

Response from EC2 describe_instances API

get_instances(self, filters: list = None, instance_ids: list = None) list[source]

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

Parameters
  • instance_ids -- List of ids to get instances for

  • filters -- List of filters to specify instances to get

Returns

List of instances

get_instance_ids(self, filters: list = None) list[source]

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

Parameters

filters -- List of filters to specify instances to get

Returns

List of instance ids

get_instance_state(self, instance_id: str) str[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(self, instance_id: str, target_state: str, check_interval: float) None[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?