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, filters=None)[source]

Get EC2 instance by id and return it.

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

  • filters (Optional[List]) – List of filters to specify instances to get

Returns

Instance object

Return type

ec2.Instance

stop_instances(self, 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(self, 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(self, 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(self, filters=None, instance_ids=None)[source]

Describe EC2 instances, optionally applying filters and selective instance ids

Parameters
  • filters (Optional[List]) – List of filters to specify instances to describe

  • instance_ids (Optional[List]) – List of instance IDs to describe

Returns

Response from EC2 describe_instances API

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

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

Parameters
  • instance_ids (Optional[List]) – List of ids to get instances for

  • filters (Optional[List]) – List of filters to specify instances to get

Returns

List of instances

Return type

list

get_instance_ids(self, filters=None)[source]

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

Parameters

filters (Optional[List]) – List of filters to specify instances to get

Returns

List of instance ids

Return type

list

get_instance_state(self, 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(self, 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?